append on click id from button jquery -
hello friends trying id of button on click whith jquery , append in bottom of href try .append don´t
i have
<button class="btn1" id="5" type="button">click me</button> <button class="btn1" id="3" type="button">click me</button> <a href="www.example.com/{id]" class="dellink">delete</a>
this works need id of botton
$("btn1").click(function(){ $(".delllink").attr("href", "http://www.example.com/"); });
you way, if want keep url element.
$("button.btn1").click(function() { var url = $("a.dellink").attr("href"); url = url.substr(0, url.lastindexof("/") + 1) + $(this).attr("id"); $("a.dellink").attr("href", url); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="btn1" id="5" type="button">click me</button> <button class="btn1" id="3" type="button">click me</button> <a href="www.example.com/{id}" class="dellink">delete</a>
otherwise can more static too:
$("button.btn1").click(function() { $("a.dellink").attr("href", "http://www.example.com/" + $(this).attr("id")); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="btn1" id="5" type="button">click me</button> <button class="btn1" id="3" type="button">click me</button> <a href="www.example.com/{id}" class="dellink">delete</a>
Comments
Post a Comment