user3111151
user3111151

Reputation: 57

Jquery replace text inside nested tags

I have something like <p> <b> old</b> </p>

I want to replace current text inside bold tag such that result is <p> <b> new</b> </p> tag when user clicks on the parent .

I am using jquery like $(this > "b").text("new"); and $(this).children("b").text("new"); but it is not working?

Any help is appreciated..

Upvotes: 1

Views: 187

Answers (3)

Jiminyjetson
Jiminyjetson

Reputation: 121

$(this).find("b").html("new");

should do the trick, assuming there is a click handler on the p element.

Upvotes: 3

arpad
arpad

Reputation: 539

You can add an id to the P tag for the select and use something like this:

$("#p").children("b").text("new");

Check this fiddle : http://jsfiddle.net/zrvmk/

Upvotes: 1

Dropout
Dropout

Reputation: 13866

Take a look at this simple jsFiddle

Find the child element by using children() method that is specified to your element - in this case b. For inner HTML content use html() method with the content you require specified.

Docs:

http://api.jquery.com/children/

http://api.jquery.com/html/

Upvotes: 1

Related Questions