Jquery is a simple example of adding a click event to a DIV, jqueryclick

Source: Internet
Author: User

Jquery is a simple example of adding a click event to a DIV, jqueryclick

Today, when I was doing a lottery activity, I made up a prompt directly after I did not win the lottery. Then I added an event to the div. Let's take a look at this example.

Html

<a href="javascript:void(0);" id="click_ms" ></a>

Jquery events

$ ('# Click_ms'). click (function () {// alert (1); $. post ("ajax. php", {"time": <? = $ Starttime?> }, Function (data) {if (data = 1) {tusi ('Congratulations! You have one movie! ');} Else if (data = 2) {tusi (' sorry, you are not in the middle. Please try again tomorrow! ');}});})

See the core sentence above

$ ("# Click_ms"). live ("click", function () {tusi ('sorry you have not selected it. Please try again tomorrow! '); Return false ;});

This is to tell # click_ms to bind a click event, and then a prompt will pop up after clicking it, and then return false so that the following event will not exist. In fact, the generated html is as follows:

<A href = "javascript: void (0);" id = "click_ms" onclick = "tusi! '); Return false; ">  </a>

In this way, we can achieve our goal. Of course, there is also such an approach.

$('div').click(function () {alert(this.innerText);});

The results are the same.

The simple example of adding a click event for the DIV in Jquery above is all the content shared by the editor. I hope to give you a reference and support for the help house.

Related Article

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.