JQuery: click () function not working on <a> .. element why?
I cannot call this click on this item.
$(this).find('.views-field-field-cover-fid').find('a.imagecache-coverimage').click();
The jQuery path is correct. Indeed, if I print it, it gives the correct element:
console.log($(this).find('.views-field-field-cover-fid').find('a.imagecache-coverimage'));
But for some reason, the click () function does not work on it. thank
+3
3 answers
EDIT:
Now I see that you want to visit the hrefitem a.
Do it:
window.location = $(this).find('.views-field-field-cover-fid').find('a.imagecache-coverimage').attr('href')
Patrick, a function .click()behaves differently depending on how it is used.
If you are hoping to run the 'click' event handler for the element you selected, then you are using it correctly, but first you will need to provide some functions to this element.
( ) .click(). , . , DOM :
$(document.ready(function() {
$('.views-field-field-cover-fid')
.find('a.imagecache-coverimage')
.click(function() {
alert('I was clicked!');
});
});
, , , .
$(this).find('.views-field-field-cover-fid')
.find('a.imagecache-coverimage')
.click();
+4
http://api.jquery.com/trigger/
: , , , , .click() .trigger('click') . .
$(this).find('.views-field-field-cover-fid a.imagecache-coverimage')
.bind("click", function(){
window.location.href = $(this).attr('href');
});
!
$(this).find('.views-field-field-cover-fid a.imagecache-coverimage')
.trigger('click');
( .click();)
+4