The jquery click () method simulates the solution that the click event does not take effect for tag.

Source: Internet
Author: User

The jquery click () method simulates the solution that the click event does not take effect for tag.

How to use a label normally

<A href = "www.phpernote.com"> </a>

Problem Analysis

Clicking tag A does not trigger the jump to the specified link. That is to say, we usually click the text in tag. To simulate A tag event by using JS, you must first add elements that can be captured by JS to the text in tag A, and then use JS to simulate and click the element.
Print $ ("a") [0] And get the http://www.phpernote.com, but in fact $ ("a") [0] is an object, maybe a DOM object is more appropriate.

Solution

Solution 1

Document. getElementById ("abc"). click ();

Use the native DOM element to operate the tag and call the native click () method;

Solution 2

$ ("# Abc") [0]. click ();

Convert a jquery object to a native DOM object

Summary

To simulate a click event, use the native DOM element to call the click () method;

Jquery objects cannot be called. Therefore, we recommend that you use native DOM objects to simulate clicks in future development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.