jQuery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    jQuery

    Hello,

    Why it is not working?

    Code:
    <script>
    $( "p" ).click(function() {
      var htmlString = $( this ).html();
      $( this ).text( htmlString );
    });
    $("p").click(function(){
      alert("The paragraph was clicked.");
    });
    </script>

    Code:
     
    <p>
      <b>Click</b> to change the <span id="tag">html</span>
    </p>
    <p>
      to a <span id="text">text</span> node.
    </p>
    <p>
      This <button name="nada">button</button> does nothing.
    </p>
    Last edited by oll3i; Feb 12 '14, 02:57 PM. Reason: add more code
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #2
    Code:
    1
    2
    3
    4
    5
    window.onload = function() {
     
        alert( "welcome" );
     
    }
    works

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Why it is not working?
      because you call the script before the paragraphs are created.

      Comment

      Working...