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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -