byronyasgur
byronyasgur

Reputation: 4737

How would I refactor this piece of jQuery

How could this code be better written? I mean I'm targeting a parent of a child of a parent. I don't know how to do it but it seems like there might be a more elegant way to do it.

$('.flex-overlay')
    .children('.fluid-width-video-wrapper')
    .parent('.flex-overlay')
    .css({
        'border': '1px solid red',
        });

Upvotes: 2

Views: 64

Answers (1)

Ram
Ram

Reputation: 144669

You can use has method:

$('.flex-overlay')
     .has('.fluid-width-video-wrapper')
     .css({ 'border': '1px solid red'});

Upvotes: 5

Related Questions