Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking a link with jQuery

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>
like image 629
Ladineko Avatar asked Dec 19 '12 14:12

Ladineko


People also ask

How do you hyperlink in jQuery?

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 .

How do you call a click method in jQuery?

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.

How do you trigger a click?

Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.

What is click in 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.


1 Answers

$( selector ).click()

As in jQuery docs:

When .click() is called without arguments, it is a shortcut for .trigger("click").

like image 154
moonwave99 Avatar answered Sep 17 '22 22:09

moonwave99