How can I get id of anchor tag specified in li tag?
My code is:
<li name="cmspage"><a href="#" id ="<?php echo $data ->page_id; ?>"><?php echo $data ->page_title; ?></a></li>
How can I get id of anchor tag specified in li tag?
My code is:
<li name="cmspage"><a href="#" id ="<?php echo $data ->page_id; ?>"><?php echo $data ->page_title; ?></a></li>
From what little you've shown in your question, it would be:
var id = $("li[name=cmspage] > a").attr("id");
More in the CSS selectors spec and the jQuery API.
You need to select li tag together with anchor as following code :
<script>
$(function(){
var id = $('li a').attr('id');
alert(id);
});
</script>
With $("li a").attr("id")
:
alert( $("li a").attr("id") )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul><li name="cmspage"><a href="#" id ="id1">Some title</a></li></ul>