Is there a way in jQuery to append to the current value of an attribute without storing it in a variable first? For example:
$(document).ready(function() {
$("#btn").click(function() {
// get the link currently
var linkCurrent = $("#link").attr("href");
// update link
$("#link").attr("href", linkCurrent + "/added");
// show the link
$("#newLink").text($("#link").attr("href"));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="www.google.com" id="link">Link to google</a>
<input type="button" value="Click me many times and look at new link" id="btn">
<p id="newLink">new link</p>
Something similar to the code above, but I am curious if jQuery provides a way to automatically append to the current attribute value without the need to store it in a variable first.