How to use ID selector after jQuery html()

Posted by user555617 on Stack Overflow See other posts from Stack Overflow or by user555617
Published on 2010-12-28T05:32:21Z Indexed on 2010/12/28 5:53 UTC
Read the original article Hit count: 227

Filed under:
|
|

It's amazing to try to understand why the function alert("hello") is not generated after clicking more than once... There is some method to do this function is executed?

Note that doesn't work after update using html() involving id "press" in button.

Any idea? See: http://jsbin.com/atuqu3

JavaScript:

  $(document).ready(function (){
      $("#press").click(function() {
          $("#relation-states").html('<select id="state" name="state"> <option value="Texas">Texas</option> </select><button id="press" type="button" title="" aria-haspopup="true" style="width: 175px;"><span>Select an item</span></button>');;
          alert("hello");
      });
  });

HTML:

  <div id="relation-states">
  <select id="state" name="state">
  <option value="New York">New York</option>
  </select>
  <button id="press" type="button" title="" aria-haspopup="true" style="width: 175px;"><span>Select an item</span></button>
  </div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery