Reputation: 57
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
Reputation: 121
$(this).find("b").html("new");
should do the trick, assuming there is a click handler on the p
element.
Upvotes: 3
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
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/
Upvotes: 1