On Aug 25, 2007, at 1:10 AM, atomicnuke wrote:
<script type="text/javascript" src="jquery-1.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#comments span h5 a").click(function(){
var author = $(this).parent("span").next("p").text();
alert(author);
})
});
</script>
</head>
<body>
<div id="comments">
<div id="5"><span><h4>Minion</h4><h5>(<a href="#">Reply</a>)</h5></
span><br>
<p>Back to normal status</p>
</div>
</div>
I'm trying to figure out how to grab the text between the <p> tags
when reply is clicked. I know I got the reply link targeted. I first
just had an alert, but tried going further. At first I just had $
(this).next("p").text(); but thought maybe I needed to go to the
parent, then move on, but it just shows a blank alert box.
You could try something like this:
$(document).ready(function() {
$('h5 > a').click(function() {
var txt = $(this).parents('div:first').next().text();
alert(txt);
return false;
});
});
This goes "up" the DOM to the first div that is an ancestor of the
clicked item, then goes to the next sibling and grabs its text.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com