Forum Moderators: open

Message Too Old, No Replies

Looping through all tagnames AND one ID

         

csdude55

1:23 am on Jun 8, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a loop like this:

$('p').each(function() { ... });

But how do I set it to loop through all of the p tags AND $('#whatever')?

I'm currently doing this, but there has to be a way to do them both at once:

$('p').each(function() {
runFunc($(this));
});

if ($('#whatever').length) {
runFunc($('whatever'));
}

Fotiman

2:44 am on Jun 8, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The selector is just how you would write it in CSS to style p elements and ID 'whatever':
p, #whatever

So:
$('p, #whatever').each(...)