Trigger click event of an anchor tag with javascript/jquery


*

*

getElementsByClassName doesn"t return an element but a NodeList which may contain more than one element.

Bạn đang xem: Trigger click event of an anchor tag with javascript/jquery

You may vị this :

document.getElementsByClassName("some-iclass")<0>.click();or if you want to click all elements :

var danh sách = document.getElementsByClassName("some-iclass");for (var i=0; iBut as you use jQuery, it would be simpler lớn do

$(".some-iclass").click();but only when the click sự kiện handler was added with jQuery (in other cases, lượt thích for example in case of an href attribute, use the standard dom functions).


chia sẻ
Improve this answer
Follow
edited Oct 17 "13 at 12:20
community wiki
2 revsdystroy
3
showroom a phản hồi |
1
$(document).ready(function() $(".some-iclass").trigger("click"); );
chia sẻ
Improve this answer
Follow
answered Oct 17 "13 at 11:57
*

coolguycoolguy
7,69899 gold badges4343 silver badges7171 bronze badges
showroom a bình luận |
1
Simple with jquery $(".some-iclass").click();

if you have a lot of elements with this class - point to lớn the wanted element:i.e. $($(".some-iclass")<0>).click();


mô tả
Improve this answer
Follow
edited Oct 17 "13 at 12:04
*

SidOfc
4,40933 gold badges2525 silver badges4747 bronze badges
answered Oct 17 "13 at 11:58

griffon vulturegriffon vulture
6,00666 gold badges3434 silver badges5656 bronze badges
địa chỉ a bình luận |
1
for auto-clicking a button or a link

""

this works...:)


nội dung
Improve this answer
Follow
edited Jan 17 "14 at 13:32
answered Jan 17 "14 at 13:25
user3206770user3206770
1122 bronze badges
địa chỉ cửa hàng a phản hồi |
0
if you want khổng lồ autoclick a link and you are using jQuery, you could use

$(".yourClass").click();if you need this to lớn be one link in a collection of multiple links, you could bởi this:

$($(".yourClass")<0>).click();Where 0 is the index of the element in the jQuery object.

document.getElementsByClassName("yourClass"); does not work in older browsers so it"s best khổng lồ use jQuery here for cross-browser compatibility.

Xem thêm: Trồng Hoa Hồng Tỉ Muội Trong Chậu !, Hoa HồNg Tỉ MuộI


share
Improve this answer
Follow
answered Oct 17 "13 at 11:59
SidOfcSidOfc
4,40933 gold badges2525 silver badges4747 bronze badges
showroom a comment |
0
For me, I managed to make it work that way. I deployed the automatic click in 5000 milliseconds và then closed the loop after 1000 milliseconds. Then there was only 1 automatic click.


giới thiệu
Improve this answer
Follow
answered Feb 7 "17 at 13:01
Naiguel DeveloperNaiguel Developer
30333 silver badges33 bronze badges
showroom a comment |

Your Answer


Thanks for contributing an answer khổng lồ Stack Overflow!

Please be sure to answer the question. Provide details & share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using thư điện tử and Password
Submit

Post as a guest


Name
e-mail Required, but never shown


Post as a guest


Name
thư điện tử

Required, but never shown


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy & cookie policy


Not the answer you're looking for? Browse other questions tagged javascript jquery or ask your own question.


The Overflow Blog
Featured on Meta
Visit chat
Related
3134
How can I change an element's class with JavaScript?
1927
Abort Ajax requests using jQuery
2309
How vày I chop/slice/trim off last character in string using Javascript?
2127
Get selected value in dropdown list using JavaScript
1434
How can I select an element by name with jQuery?
1818
Scroll lớn the top of the page using JavaScript?
1714
Convert size data to JavaScript object with jQuery
2430
Get selected text from a drop-down list (select box) using jQuery
641
Get class name using jQuery
2980
pretty-print JSON using JavaScript
Hot Network Questions more hot questions

Question feed
Subscribe lớn RSS
Question feed to lớn subscribe to lớn this RSS feed, copy & paste this URL into your RSS reader.


lang-js
Stack Overflow
Products
Company
Stack Exchange Network
site thiết kế / biểu tượng logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.2.3.41361


Stack Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.