By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

jQuery

oll3i
100+
P: 679
Hello,

Why it is not working?

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. $( "p" ).click(function() {
  3.   var htmlString = $( this ).html();
  4.   $( this ).text( htmlString );
  5. });
  6. $("p").click(function(){
  7.   alert("The paragraph was clicked.");
  8. });
  9. </script>

Expand|Select|Wrap|Line Numbers
  1.  
  2. <p>
  3.   <b>Click</b> to change the <span id="tag">html</span>
  4. </p>
  5. <p>
  6.   to a <span id="text">text</span> node.
  7. </p>
  8. <p>
  9.   This <button name="nada">button</button> does nothing.
  10. </p>
Feb 12 '14 #1
Share this Question
Share on Google+
2 Replies


oll3i
100+
P: 679
Expand|Select|Wrap|Line Numbers
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. window.onload = function() {
  7.  
  8.     alert( "welcome" );
  9.  
  10. }
works
Feb 12 '14 #2

Dormilich
Expert Mod 5K+
P: 8,639
Why it is not working?
because you call the script before the paragraphs are created.
Feb 12 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.