PHP add class to html div

安稳与你 提交于 2019-12-22 14:38:37

问题


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
}

回答1:


Try this code :

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



回答2:


<?php

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

?>


来源:https://stackoverflow.com/questions/11852425/php-add-class-to-html-div

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!