When I click on a div, I would like to change the text inside it to New Text.
How can I do that with jquery
$('#mydiv').????
When I click on a div, I would like to change the text inside it to New Text.
How can I do that with jquery
$('#mydiv').????
$('#mydiv').click(function(){
this.innerHTML = "New Text";
});
if you have something to chain, you can do it this way,
$('#mydiv').click(function() {
$(this).html("New Text") // can include html tags, use .text() for text only.
.animate({marginLeft: '+=10'}); // chain an animation...
});
Bind an event and handle it:
$('#mydiv').click(function() {
$(this).html("New Text");
});
Or use bind
$('#mydiv').bind("click", function() {
$(this).html("New Text");
});
Or live
$('#mydiv').live("click", function() {
$(this).html("New Text");
});
References