I have a little script i made but im wondering if its possible for me to trigger a link on the page with just 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>
Specify a URL using attribute selectors ready(function(){ $('a[href=http://www.google.com]').click(function(){ window. open(this. href); return false; }); }); In this example, we are targeting a href attribute with a value of http://www.google.com .
To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.
Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.
jQuery click() MethodThe click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.
$( selector ).click()
As in jQuery docs:
When .click() is called without arguments, it is a shortcut for .trigger("click").
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