0

I am trying to target a div nested within some php with js, but no matter what I do, I can't seem to target it. Here is the code for reference: php:

echo "<li>"."<div id=\"countryclick\">". "<a href=\"?Continent=$Continent&Country=$Country\">" . $Country . " ". "</a>" . "</div>"."</li>";

js:

$("#countryclick").click(function(){
    $("#country").hide();
    $("#city").show();
});

Any ideas? Thanks in advance!

No_name
  • 2,732
  • 3
  • 32
  • 48

4 Answers4

2
div#countryclick 

is created on the fly so you can use .live of jQuery. Like:

$("#countryclick").live("click",function(){
   //code here
})
zhujy_8833
  • 561
  • 4
  • 6
0

I am not sure if you are creating div dynamically or not. If you are creating it dynamically you have to use live method as follows:

$("#countryclick").live("click",function(){
    $("#country").hide();
    $("#city").show();
});

Please check it out.

Kalpesh Patel
  • 2,772
  • 2
  • 25
  • 52
0
<li>
    <div id="countryclick">
      <a href="?Continent=<?php echo $Continent; ?>&Country=<?php echo $Country; ?>">
        LINK HERE
      </a>
    </div>
</li>
<div id="country">country</div>
<div id="city">city</div>

$("div#countryclick").live("click",function(){
    $("#country").hide();
    $("#city").show();
});

this should be working.

zaw
  • 684
  • 1
  • 11
  • 30
0

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. If you are using some older versions of jQuery you should use .delegate() in preference to .live().

Visit here live() and Here on()

ScoRpion
  • 11,364
  • 24
  • 66
  • 89