Skip to content Skip to sidebar Skip to footer

Jquery: Select Paragraphs That Only Contain " "

Possible Duplicate: Remove elements with only a   space using jQuery Wordpress does this thing with adding

 

when doing a line-break in the

Solution 1:

Add this to your functions.php file if you have access to the theme files.

functionuser_content_replace($content) {
    return str_replace('<p>&nbsp;</p>','<p class="example">&nbsp;</p>',$content);
}
add_filter('the_content','user_content_replace', 99);

I made it insert a class instead of removing.

Solution 2:

This would work to select the paragraphs in question:

$("p").filter(function() {
    return $.trim($(this).html()) == '&nbsp;';
});

Solution 3:

You can do something like this

$(document).ready(function(){ 
            $("p").each(function(){
                if($(this).html()=="&nbsp;") {
                    alert($(this).attr('id'));
                }   
            });
        });

And the HTML I used was

<pid="test"class="les">&nbsp;</p><pclass="les"id="test1">aaaa &nbsp;</p>

So it should alert only p with id test

Hope this helps

Post a Comment for "Jquery: Select Paragraphs That Only Contain " ""