tags:

views:

56

answers:

2

Hi, i m new to JQuery... In my App, i have some 5 divs..while clicking any one of the div ,i want to check whether any other divs have been clicked before...

actually in my code..I have Text, Textarea Dropdown .. while clicking on Text/textarea/dropdown for the first time i.e..,(i need to check whether any of the others including its own has been clicked before).so tat i can proceed based on tat

Even if i use what u said having a variable=1 ..There arose an issue that while clicking on any of text/textarea/dropdown ,i want to check whether the one i m clicking and the others have clicked before....

.Please suggest me...

+1  A: 

Just track it in a variable. The example assumes that "clicked" is defined something (a closure that generates the event handler function would be good) and initilised to a value of "0" or other non-true value.

if (clicked) {
  a();
} else {
  b();
}
clicked = 1;
David Dorward
actually in my code..I have Text,Textarea,Dropdown ..while clicking on Text/textarea/dropdown for the first time it should do one thing..Even if i use wat u said haing a variable=1 ..THere arise an issue tat while clicking on any of text/textarea/dropdown i need to check whether any of the others including its own has been clicked before.....
Aruna
You use _a_ variable not a variable per control
David Dorward
Ya i have used only a single variable ...If i used what you said to have a variable for each control,then do i have to check all those(excluding the one i m clicking) variables are clicked before..???
Aruna
At no point did I say to use a variable for each control. I said to use a single variable. If any control is clicked, test that one variable to see if it is true, and then set it so that it is (along with doing whatever else you want to do on the first click).
David Dorward
A: 

I don't know what exactly you are trying to do. But one possible solution could be to define new attribute for each div, let say "was_clicked" and when you can do the following:

div.click( function(event)
{
  if ( $( "div[was_clicked=true]").length > 0)
   // some of the div was clicked
   // you can iterate over each clicked div by  $( "div[was_clicked=true]").each( ...)
  $(this).attr( "was_clicked", "true");
});
Artem Barger