Suresh Ponnukalai
Suresh Ponnukalai

Reputation: 13988

Applying CSS for mutiple id is not working in jquery

I am trying to apply width for my divisions using jquery. The following code is working fine for me.

$('#bodycontainer').css('width','300px'); 
$('#footer').css('width','300px');

But when combine both id's and keep it as a single rule is not working. see below.

$('#bodycontainer','#footer').css('width','300px');

What i am doing wrong here??

JSFIDDLE

Upvotes: 2

Views: 67

Answers (2)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67187

The way you have used the multiple selector is wrong

Try,

$('#bodycontainer,#footer').css('width','300px');

DEMO

Upvotes: 5

Jai
Jai

Reputation: 74738

you have to use this way:

$('#bodycontainer, #footer').css('width','300px');

Here you have selected multiple selectors with , separated in a single string.


Issue with your code:

$('#bodycontainer','#footer')

Using this way is says that find me #bodycontainer in #footer. The second one is treated as a context.

Prooved

so what that mean is this:

$('#bodycontainer','#footer') === $('#footer').find('#bodycontainer')

Both are equal to this.

Upvotes: 1

Related Questions