Is is possible to update the text 'changethis' in below div using jquery ? I don't think the .html method will suffice here since I just want to update part of the html, not all of it.
<div id="test">
<a title="http://stackoverflow.com" href="http://stackoverflow.com">changethis</a>
</div>
.text()
or .html()
won't work for you, giving an example - d_inevitable 2012-04-03 20:31
This
$("#test a").html("changed it");
will produce:
<div id="test">
<a title="http://stackoverflow.com" href="http://stackoverflow.com">changed it</a>
</div>
#test a
is just a selector that selects all a
s within #test
- just the same as for css - d_inevitable 2012-04-03 20:55
$('#test a').html('newText');
Or
$('#test a').text('newText');
You should be able to use Jquery's builtin .text() function
E.G. $('#test a').text('New Text');
I would advise either using a second div element within the link. Or if possible select the link element itself.
The other option is to hardcode the anchor tag into your write code
.html("<a title='http://stackoverflow.com' href='http://stackoverflow.com'>"+newtext+"</a>");
.html('<a title="http://stackoverflow.com" href="http://stackoverflow.com">'+newtext+'</a>');
Adam Merrifield 2012-04-03 20:28