I have following html code. In my page there are many tag which have class=’posta’ but what i want assign onclick event only to which have post attribute.
<ul class="posts_li">
<li>
<a href="#" class="posta" post="status">Post</a>
</li>
<li>
<a href="#" class="posta" post="act">Act</a>
</li>
<li>
<a href="#" class="posta" post="event">Event</a>
</li>
<li>
<a href="#" class="posta" post="news">Create News</a>
</li>
</ul>
My Jquery Code for assigning an event is here
$(".posta").click(function(){
alert("here");
if($(this).attr("post")){
alert($(this).attr("post"));
}
});
Use can use attribute selectors
[propertyname]to select only nodes that have that property.