Monday, 15 February 2010

jquery - Determine whether a link is text or an image -



jquery - Determine whether a link is text or an image -

i need write if statement based on whether or not href contains text link or image link. if content of link :

jquery(document).ready(function($){ $('a').click(function(event) { var $linkcontent = $(this).html(); // doesnt work.. 1 of things tried // var imgsrc = $(this).attr('src'); }); })

i thought go other way , text content :

var linkcontent = $(this).text();

then when alert variable shows text text links , blank images. great! still isnt working me. going write rules based on .length if alert lengths image links still giving me integer though if alert .text() blank. confused!

this in click handler anchor element because it's attached anchor elements in code. do

$('a').click(function(event) { var $this = $(this); if($this.find("img").length) { //searches within anchor element img element //it's image } else { //no images in anchor tag } })

jquery

No comments:

Post a Comment