The original html is only 2 hyperlink.
I want to
- Add each button behind each hyperlinks.
- when click button show each hyperlink value.
if i click first button,will alert "ahref".
if i click second button,will alert "bhref".
but result is both buttons alert "bhref".
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('a').each(function(){
get_href=$(this).attr("href");
new_ele = $("<button type='button'>test</button>");
new_ele.click(function(){
alert(get_href);
});
$(this).append(new_ele);
});
});
</script>
<body>
</body>
<a href="ahref" >a</a>
<a href="bhref" >b</a>
</html>