Search code examples
jqueryhideparent

Hide via jquery all instances of a specific line of html


I want to hide, via jquery, all instances of only this exact string: <p>description</p>

I must be missing something obvious:

http://jsfiddle.net/deekster/pSJ95/

Thanks.

<p>name</p>
<p>description</p>
<p>address</p>

$('p contains(description)').parent().remove();


Solution

  • I want to hide, via jquery, all instances of only this exact string: <p>description</p>

    Eventhough you have issue with the selector, contains will not do an exact match, it will do a wildcard match to match all element containing the string description as its content. To do an exact macth you can do a filter.

    $('p').filter(function () {
        return this.innerHTML === "description";
    }).remove(); //if you want to just hide them use .hide(), .remove() will remove it from DOM.
    

    Demo