Can you tell me, how to get data from a link attribute?
Example :
<a href="#" target="2">link</a>
I want get the data from 'target' attribute to send to server.
Can you tell me, how to get data from a link attribute?
Example :
<a href="#" target="2">link</a>
I want get the data from 'target' attribute to send to server.
You can also do the same thing in jQuery using the .attr()
function.
var target = $("#link").attr("target");
console.log(target);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" target="2" id="link">link</a>
You can use .getAttribute()
like below. (I used document.getElementById()
to get the element, and .getAttribute
to get the value of the target
attribute)
var target = document.getElementById("link").getAttribute("target");
console.log(target);
<a href="#" target="2" id="link">link</a>