Gotjosh
Gotjosh

Reputation: 1049

Remove text from a p tag and add a class with jquery

What I'm triying to accomplish is that everything there's a p tag with word "border" on it it will remove the text inside it (the word border) and add a class to the P. So far this works for finding the p and adding the class. How can I remove the text?

$('#main-body-content').find('p').filter(':contains(border)').addClass("border");

Upvotes: 1

Views: 1030

Answers (2)

Posto
Posto

Reputation: 7550

try this

// find all divs that have attribute class
$('p').filter(function() { return $(this).attr('class'); }).each(function() {
    $(this).html('');
});

Upvotes: 0

Vivek
Vivek

Reputation: 11028

try this......

$('#main-body-content').find('p').filter(':contains(border)').text("").addClass("border");

DEMO

Upvotes: 4

Related Questions