Clicking a link using jQuery

I have a little script i, but they are wondering if it is possible that I can only call the link on the page with jQuery.

Js

var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } $('a.more').each(function() { var self = this; if (vars['deeplink'] == 'true') { /* this must trigger the link and that will trigger $(self).click */ } $(self).click(function() { var theid = self.href.split('#').pop(); var row = document.getElementById('info-art' + theid); var now = typeof(row.style.display) != 'undefined' ? row.style.display : 'none'; $('tr.info').each(function() { this.style.display = 'none'; }); if (now == 'none') { row.style.display = $.browser.msie ? 'block' : 'table-row'; } }); }); 

HTML

 <td><a class="more" href="#8714681006955">[+]</a></td> 
+6
source share
3 answers

You can use jQuery.trigger for this jquery documentation

+5
source
 $( selector ).click() 

Like in jQuery docs :

When .click () is called with no arguments, this is a shortcut for .trigger ("click").

+7
source

Based on โ€œis it possible for me to launch a link on a page using only jQueryโ€, I assume that you want to trigger your own click event (as an alternative to the code you posted). If I understand this correctly, you may find the answer below useful.

This is a complete copy of Karl Swedberg answer

Using .trigger ('click') will not trigger its own click event. To simulate a default click, you can bind the click handler as follows:

 $('#someLink').bind('click', function() { window.location.href = this.href; return false; }); 

where "someLink" is the actual selector of your choice.

You can then run this related click handler, if you want, based on a different interaction.

 $('input.mycheckbox').click(function() { if (this.checked) { $('#someLink').trigger('click'); } }); 

http://api.jquery.com/trigger/#comment-48277488

Be sure to keep the original author if you find this useful.

+2
source

All Articles