2

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

2 Answers 2

5

The way you have used the multiple selector is wrong

Try,

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

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Please don't use code spans (like this) for phrases like "multiple selector", they are only meant for code within sentences.
1

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.

1 Comment

Its okay @SureshPonnukalai, I hope this helped you understanding of the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.