Home > Web Front-end > JS Tutorial > body text

jQuery simulates clicking on A mark example reference_jquery

WBOY
Release: 2016-05-16 16:51:59
Original
1145 people have browsed it

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).
  • Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template