jquery change different text in divs
Hallo,
I have three different divs and a paragraph in each one of them.
I would like to click on div 1 and text 1 changes - if I click on div 2, text 2 changes while text 1 is changing back to normal...
Just the text in开发者_如何学编程 the div where I just clicked should change. Since I am a newbie to jquery I can just achieve that all the texts are changing, but not the single one.
Who can help me?
Thanks!
This will do the trick - first populate data for each div with the original content, then bind click event that sets everything back to original data, and sets itself to new text:
http://jsfiddle.net/billymoon/zAhJv/
$('div').each(function(){
$(this).data({original:$(this).text()})
})
$('div').click(function(){
$('div').each(function(){
$(this).text($(this).data('original'))
})
$(this).text('new text')
})
精彩评论