Pullapooh
Pullapooh

Reputation: 161

PHP add class to html div

i would like to add a class to my html (.complete) with php:

if( get_field('to-do-repeater') )
{
    Add (complete) class to <div class="to-do to-do-wrap"> should be <div class="to-do to-do-wrap complete">
}
else
{
    Do nothing
}

Upvotes: 4

Views: 73657

Answers (3)

Try this code: `

<div class="to-do to-do-wrap <?php if(get_field('to-do-repeater') echo "complete"?>">

Upvotes: 0

Oussama Jilal
Oussama Jilal

Reputation: 7749

Try this code :

<div class="to-do to-do-wrap<?php echo get_field('to-do-repeater') ? ' complete' : '' ?>"></div>

Upvotes: 8

PriestVallon
PriestVallon

Reputation: 1518

<?php

echo "<div class=\"to-do to-do-wrap ";
if(get_field('to-do-repeater'))
{
    echo "complete";
}
echo " \"></div>";

?>

Upvotes: 3

Related Questions