Find an Anchor tag inside a Paragraph tag.
I have the following markup which I need to bind a click event to the <a>
tag below.
How can i achieve this?
<p class="people_rt_link2" id="test">
<a href="#" title="2011">2011</a>
<p style="padding-left: 3px; margin: 3px 0px;">
a href="http://192.168.20.24/mclarengroup/archives/928">McLaren to build £10m Big Yellow in Chiswick, West London</a>
</p>
<br>
<a href="#" title="2010">2010</a>
<br>
</p>
This is my current javascript function:
<script type="text/javascript">
$(document).ready(function() {
$('.people_rt_link2 a').click(function() {
alert('aa');
});
var data = { cat_id:<?php echo $cat_id?>,posted_year:<?php echo $posted_year?>};
jQuery.p开发者_JS百科ost("<?php echo $ajax_page_details->guid?>", data, function(response) {
$('#test').html(response);
});
});
</script>
you could possible do it by setting an id for the link.
HTML:
<a href="" id="link123">123</a>
Javascript:
$("#link123").click(...);
Have a look at the jquery documantation specially for selectors:
http://api.jquery.com/category/selectors/
You HTML is poorly formed. If you want those styles, apply them directly to the element itself (as shown) or wrap it in a span rather than another paragraph tag.
I also opened an <a>
tag for you and self closed your </br>
http://jsfiddle.net/pSGRE/
精彩评论