<a href="" id="a1">myval</a>
How to get the value which is in between anchor tag ie; here "myval" and then specify that value to a hidden box.I tried do it with my piece of code but couldn't figure it out.pls help
<script type="text/javascript">
$(document).ready(function(){
$("#a1").click(function(e){
//var str=$("#a1").getVal();
alert('hello');
}
});
</script>
To get the value of a script element, use the . html() method. As of jQuery 1.4, the . text() method returns the value of text and CDATA nodes as well as element nodes.
To get all the anchor tags or links from the HTML document or the DOM, you can use the document. links property. You can get all the links using the document. links property using JavaScript.
To find anchor tag in div, use a selector and the addClass() method adds a class using jQuery.
var a1_text = $('#a1').text();
var a_href = $("#a1").attr("href");
You can use .text()
to get the innertext of the anchor tag and .val()
to store the value to a textbox.
$(function(){
$("#a1").click(function(){
$("#yourtextbox").val($(this).text());
});
});
<a href="" id="a1">myval</a>
you can use var yourValue= $('#a1').text();
it will works fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With