Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check class child class is available or not jquery [closed]

Tags:

jquery

<div class="formSortable ui-sortable">
    <div id="formItem_c_firstName" class="formItem leftLabel selected">
        <label class="varcharIcon">First Name</label>
        <div class="formInputBox">
            <input type="text" id="Name" >
         </div>
    </div>
</div>

formSortable class child class formItem having selected class or not my jquery is

if ($('.formSortable').find('formItem').hasClass('selected')) {
                   alert("hi");
               }
like image 825
Dhanush Bala Avatar asked Dec 01 '22 16:12

Dhanush Bala


2 Answers

This:

if( $('.formSortable').find('.formItem.selected').length > 0 ) {
    alert( 'hi' );
}

Or this:

$('.formSortable').find('.formItem.selected').length == 0 || alert( 'hi' );

Should work fine.

But if per the title you really meant child of '.formSortable' then use .children() instead of .find():

if( $('.formSortable').children('.formItem.selected').length > 0 ) {
    alert( 'hi' );
}

Or:

$('.formSortable').children('.formItem.selected').length == 0 || alert( 'hi' );
like image 184
PeterKA Avatar answered Dec 04 '22 05:12

PeterKA


if ($('.formSortable').find('.formItem').hasClass('selected')) {
                   alert("hi");
               }

you have missed the . before formitem .

like image 29
Amit Kumar Avatar answered Dec 04 '22 06:12

Amit Kumar