JQuery how to have a event only triggered once on clicking a div?

There are a few ways of doing it. Firstly you can just use a marker.

There are a few ways of doing it. Firstly you can just use a marker: ... with: $("div. Sub-content.

Not-loaded"). Live("click", function() { $(this). RemoveClass("not-loaded"); ... }); Obviously you can do this the other way as well (add a class to mark that it's been loaded).

I'm not 100% the above will be handled correctly with live() in which case: $("div. Sub-content. Not-loaded").

Live("click", function() { if ($(this). HasClass("not-loaded")) { $(this). RemoveClass("not-loaded"); ... } }); will work.

Alternatively you can unbind the event. $("div. Sub-content").

Click(load_content); function load_content() { $(this). Unbind("click", load_content); ... } I'm not 100% sure that'll work with live() however (as live() may just rebind it).

It doesn't seem to work in this case, but I definitely learnt something anyway, thanks. – Ankur Dec 15 '09 at 2:15.

You can use the die method: $(". Sub-content"). Live('click', function() { $(this).

Die('click'); var id = this. Id; $. Get("InfoRetrieve", { theid:id }, function(data) { addContent(data, id) } ); }); I never tested it though.

That's going to remove all the click events. The OP only wants to make sure each div only loads once, which isn't quite the same thing. Your way would kill all click events when the first div was clicked so none others could be clicked.

– cletus Dec 14 '09 at 9:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions