jquerycss

how to select all classes in jquery?


this jquery code :

$('.menu_item_wrap')[0].style.setProperty('border-top', '1px solid #E7E7E7', 'important');

select the first class "menu_item_wrap" only . also i need it because the important Property .

if i delete the [0], the code will not work. and if i use this code :

$('.menu_item_wrap').css({"border-top": "1px !important"});

the !important doesn't work.

how to select all classes within this code :

$('.menu_item_wrap')[0].style.setProperty('border-top', '1px solid #E7E7E7', 'important');

Solution

  • You'd have to loop it:

    $('.menu_item_wrap').each((index, item) => {
        item.style.setProperty('border-top', '1px solid #E7E7E7', 'important');
    });