bdalina bdalina - 1 month ago 8
Ajax Question

Adding class to child element by parent Element ID and Child Class

I think I got this wrong "$('#groupdepID01 > .lahatkami')"
$('ID > Class')

script

$('#groupdepID01 > .lahatkami').addClass('iamSelected');


html

<div id="groupdepID01">
<input class="lahatkami" id="01" />
</div>

<div id="groupdepID02">
<input class="lahatkami" id="02" />
</div>

<div id="groupdepID04">
<input class="lahatkami" id="03" />
</div>


Expected Output should be

<div id="groupdepID01">
<input class="lahatkami iamSelected" id="01" />
</div>

<div id="groupdepID02">
<input class="lahatkami" id="02" />
</div>

<div id="groupdepID03">
<input class="lahatkami" id="03" />
</div>

Answer

Your code is working.

I suspect you did not include jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

in you project..

Run Code And After Check Developer tools or press F12

iamSelected Class Add inside id="groupdepID01"

Live Demo Here

Snippet Example Below

$('#groupdepID01 > .lahatkami').addClass('iamSelected');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="groupdepID01">
     <input class="lahatkami" id="01" />
</div>

<div id="groupdepID02">
     <input class="lahatkami" id="02" />
</div>

<div id="groupdepID04">
     <input class="lahatkami" id="03" />
</div>

For Testing Purpose Add Css In iamSelected

$('#groupdepID01 > .lahatkami').addClass('iamSelected');
.iamSelected
{
 background-color:blue;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="groupdepID01">
     <input class="lahatkami" id="01" />
</div>

<div id="groupdepID02">
     <input class="lahatkami" id="02" />
</div>

<div id="groupdepID04">
     <input class="lahatkami" id="03" />
</div>

Using jquery-3.1.1.min.js

$('#groupdepID01 > .lahatkami').addClass('iamSelected');
.iamSelected
{
  background-color:blue;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div id="groupdepID01">
     <input class="lahatkami" id="01" />
</div>

<div id="groupdepID02">
     <input class="lahatkami" id="02" />
</div>

<div id="groupdepID04">
     <input class="lahatkami" id="03" />
</div>