Home  >  Article  >  Web Front-end  >  jQuery simulates clicking on A mark example reference_jquery

jQuery simulates clicking on A mark example reference_jquery

WBOY
WBOYOriginal
2016-05-16 16:51:591146browse

I spent half an hour trying to figure this out, and then I thought it was like this.

Menu

Copy code The code is as follows:


When you click
  • , the hyperlink inside is triggered:
    Copy code Code As follows:

    // Correct choice
    $("li.menu").children("a")[0].click()
    // The following will not work
    $("li.menu").children("a").eq(0).click()

    --it will say that the parameter is wrong and the bound click event function was not found ,

    --Because eq(0) returns a jQuery object, when click() occurs, it will find the function bound to it, but there is no bound function at all, so an error is reported.

    , and [0] returns a DOM object. When click() occurs, the original behavior of the element will be executed.

    Note: [0] This is equivalent to get(0).
  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Previous article:In jQuery, use bind, live or on_jquery to bind future element events.Next article:In jQuery, use bind, live or on_jquery to bind future element events.

    Related articles

    See more