1

I am using jQuery to do something like:

$("#div1 .code").css('display','inline');

Now the problem is that when I add another element with class "code" inside div1, it does not get the CSS tag of display inline.

How can I make it so that it always updates the CSS for any new elements part of div1.

Thank you for your time.

3 Answers 3

1

make a css class in the <style type='text/css'></style> section and add that class to each div that you make. It is always best to keep styling and javascript separate, so it is easier to dbug and understand.

edit make the class .inline-div { display:inline!important } (use important if you want to make sure it takes precedence)

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

Comments

0

Look into jQuery live events. They will do exactly what you need.

1 Comment

I've looked at live elements. But what event should I bind it to?
0

$("#div1 , .code") -- the comma was missing.

look at this question

Edit: You should bind with the event that creates the new element. How is the element created?

Comments

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.