How to pass id?

The question was asked: 6 years 11 months ago   views: 17

Hello! Tell me, please, how do I pass the id (div-a) when you click on it (example below)

<div class="Content" id="div3.1" onClick="Func_Id_Div" >Folder 3.1</div>

And the execution of this function it is necessary that the "Folder 3.1" burst into a light blue color (and parallel to all other divas who have cleared the fill. Well, I think we should first all the divas from the fill brush, and after which clicked to fill. But can't register it.

Asked: angry angry 21-06-2012 в 12:27:12
onClick="Func_Id_Div(" to convey the id, but about fill don't clear without a code - makregistr makregistr 21-06-2012 в 12:46:29
All thank you very much the decision. (pushed to a good idea) and I forgot to specify that you cannot use frameworkapi (but jquery treats them sorry:))once again thank you all!!!! - Виталий44 Виталий44 21-06-2012 в 13:46:34

Answers   4

 .content {
 width: 100%;
 background-color: lightgrey;
 height: 100px;
 <div class="content" id="div3.1">Stick 3.1</div>
 <div class="content" id="div3.2">Stick 3.2</div>
 <div class="content" id="div3.3">Stick 3.3</div>

the <script>

 $(".content").click(function() {
 $(".content").css("background-color", "");
 $(this).css("background-color", "red");
</script> I understand, in the end is the need?

Answered: ivkremer ivkremer 21-06-2012 в 12:59:33

You just pass in the function itself div( ie himself) on which the event occurred:

<div class="Content" id="div3.1" onClick="Func_Id_Div(this)" >Folder 3.1</div>

the <script>
Func_Id_Div function(obj)
// Some actions with div-object....
Answered: AseN AseN 21-06-2012 в 13:40:10
But this is interesting! What a minus? Justify. --- Or is it @karmadro4 again lipil minus and ran into his hole? - AseN AseN 22-06-2012 в 13:39:37

PPC, do not you think that jQuery is too much for such a task?

Func_Id_Div function(obj) { return; }

Answered: Michael Michael 22-06-2012 в 13:31:26
 var id = $(this).attr('id');
Answered: Vfvtnjd Vfvtnjd 21-06-2012 в 12:58:00
As the same I hate that almost all of 100,500 times inicializirati $(this), do you understand what does this code do? And the main question var id = $(this).attr('id'); // wtf? what is the meaning of this line? var id =; // why is there to initialize a new jquery object? - Zowie Zowie 21-06-2012 в 13:16:14
@AlexWindHope as always support. - AseN AseN 21-06-2012 в 13:38:17