开发者

Change Text of elements by clicking it. jQuery

开发者 https://www.devze.com 2023-04-12 15:24 出处:网络
I have button and when I click it a html page loads to div with id=myDiv. Then I want to change the text of certain tags when they are clicked. Like if i click the text that is in h2 tag the text of t

I have button and when I click it a html page loads to div with id=myDiv. Then I want to change the text of certain tags when they are clicked. Like if i click the text that is in h2 tag the text of the h2 tag change to some sting.

"My Page" would be "Text Removed" after i clicked "My Page".

Been trying to use text() to change the text, but now always when i click on the area of myDiv the whole html page disappear and my div have only the string "Text Removed"

How can i access every tag开发者_C百科 in the div so i can click on single text inside of

and change it to "text removed"?


$('*', '#myDiv').live('click', function() {
    $(this).text('Text removed');
});

should do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号