javascript - jquery more click function using data attribute -


i have link multiple contents (result of db query). tried using more 1 click function, site slow, tried doing this.

the html element written php:

<img id="click" src="images/like.png" alt="" width="80%" data-event="'.$rows[$i][id].'"/> 

the jquery code:

<script>      $(document).ready(function()      {          $('#click').click(function()         {              var id = $(this).data('event');             if (window.xmlhttprequest)             {// code ie7+, firefox, chrome, opera, safari                  xmlhttp=new xmlhttprequest();                                    xmlhttp.open("get","likes.php?eid="+id+"&ip=ipaddress",true);                 xmlhttp.send();              }             document.location = "index.php";          });      }); </script> 

but works on first element...

$("#click")  

will return first element. ids need unique.

instead change class , work

$(".click")  

this return list of images

but still can above html unmodified also, won't recommend it

$("img[id^=click]") // don't use ever , know work 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -