• Resolved tasty.donuts

    (@tastydonuts)


    Hi there,

    Spent 2 days trying to figure this out (working on a little personal side project to learn about jQuery): in the code below the true condition for the “if” will cause ALL <div class="commentcount"> to read “castor” … if the condition is false it will read “pollux” on ALL <div class="commentcount">.

    I have solved this issue before by using the $(this) provided by jQuery unfortunately this time I can’t figure out how to get it in there without breaking the if / else from actually making the replacement.

    Please note that I have constructed this example to be simple, this is not production code…

    <script>
    //<![CDATA[
    
    var postID = <?php the_id() ?>;	
    
    if (postID > 0) {
    	$(".commentcount").html('castor');
    }
    
    else {
    	$(".commentcount").html('pollux');
    }
    
    //]]>
    </script>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Jquery .html() replacing EVERY class, want it to do 1 per post in loop’ is closed to new replies.