hello friends i am trying to get value from a dynamic href link . in which the three values which i pass through the href changes . actally the href is a part of image . i am getting 7 images from database . it means there are 7 href in total . so here is my problem , even if i try to extract the value from the href . only the value of the fst href is displayed in alert . here is my jquery code. for eg . i click on 3rd image then also values of the first href link is displayed .can anyone help me out ?
var a = document.getElementById('plzx');
var parts = a.search.slice(1).split('&');
var table = {};
for( var i = 0; i < parts.length; i++ ) {
var pair = parts[i].split('=');
table[pair[0]] = pair[1];
}
var id = table.id;
var a =table.a;
var pic =table.pic;
and here is my gallery code sample by which i getting values in href dynamically
<li>
<a href="<?php echo $pic;?>?id=<?php echo $id;?>&a=<?php echo $srcwidth;?>&pic=<?php echo $picID;?>" data-title="hi" data-desc=" " data-rel="group2" data-bw="<?php echo $pic;?>" class="lightbox" id="plzx" >
<img src="<?php echo $pic;?>" width="160" height="160" title="Click To View"/>
</a>
</li>
my php code .after being executed
<a id="plzx" class="lightbox" data-bw="uploads/1452243951jatin.png" data-rel="group2" data-desc=" " data-title="hi" href="uploads/1452243951jatin.png?id=3&a=796&pic=4">
<span style="position: relative;" class="tp-lightbox-element">
<img width="160" height="160" title="Click To View" src="uploads/1452243951jatin.png">
</span>
</a>
well.as far as i know unfortunately A tags cannot be identified independently..this can be avoided using divs for each A tags.
or you can get the list of all A tags from the page like this..
var lnk = td.getElementsByTagName('a')[0]
var src=lnk.href
$('.classname').click(function(){ a=this; var parts = a.search.slice(1).split('&'); var table = {};
for( var i = 0; i < parts.length; i++ ) {
var pair = parts[i].split('=');
table[pair[0]] = pair[1];
}
var id = table.id;
alert(id);
var a =table.a;
var pic =table.pic;
return false;
});
Check out this fiddle http://jsfiddle.net/yBJ6j/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.