0

I have two div's that are being placed in the DOM after the page loads, with jquery. I'm having a hard time binding one div action to showing another element. Any pointers?

  jQuery('#create-account-btn').live('click',function(){
    jQuery('#create-account').show();
    jQuery(this).hide();
  });

Create-account will now show

Eli
  • 14,779
  • 5
  • 59
  • 77
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424

1 Answers1

2

Working Demo http://jsfiddle.net/Zvd8J/

Jquery .on event read more here but only above v 1.7 : http://api.jquery.com/on/ .live here: http://api.jquery.com/live/

if you keen: What's the difference between jQuery .live() and .on()

Further if you become more keen: see here why : What's wrong with the jQuery live method?

Took liberty to jot down small html and demo for you.

Hope this helps, :)

Also note: you could do this:

$(document).on('click','#create-account-btn',function(){

});

code

$('.hulk').hide();
$('#create-account-btn').on('click',function(){
    $('.hulk').hide();
    $('#create-account').show();

  });

$('#foo').on('click',function(){
    $('.hulk').hide();
    $('#create-whatever').show();

  });

html

<div class="hulk" id="create-whatever">
hulk yada yada
</div>
  <div class="hulk" id="create-account">
ironman yada yada crea accoutn show
</div>
<input type="button" id="create-account-btn" value="click me" />

<input type="button" id="foo" value="click me to show another" />
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • If replacing `.live()` with `.on()` that's not the syntax you use (for elements loaded after dom ready). See http://api.jquery.com/live for how to port to `.on()`. – nbrooks Jul 10 '12 at 01:08
  • Hiya @nbrooks Howz it going man! `:)` cheers, I have also updated few helpful stuff for OP. – Tats_innit Jul 10 '12 at 01:10