The following is a segment of HTML in one of my pages:
<li class="prodcat-line">
<a title="foobar" class="prodcat" href="/some/url.php">Foobar</a>
</li>
I want to be able to retrieve the url of the clicked on li tag. My "jQuery fu" IS NOT WHAT IT SHOULD BE. I know how to bind the click event of li elements of class "prodcat-line", but I don't know how to extract nested tags from within the clicked item - can anyone help?
click(function(e){ var id = e.target.id; alert(id); }); }); In this way, e. target is the element you have clicked on.
$('#my-div a'). click(function() { var txt = $(this). text(); console. log(txt); });
The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page. It's either used to provide an absolute reference or a relative reference as its “href” value. Syntax: <a href = "link"> Link Name </a>
$('.prodcat-line').click(function(){
alert($('a', this).attr('href'));
return false;
});
Example here.
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