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.