Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-14-2011, 09:40 PM   PM User | #1
asmon
New Coder

 
Join Date: Apr 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
asmon is an unknown quantity at this point
adding a class to dynamically added element.

I have an element which i add dynamically, then i am trying to add a class to
that element using jquery's addClass()
Code:
$("#tabs [room_id='"+msg_room+"']").addClass("new-msg");
it works if it's a preloaded element, but not if it was added dynamically.
I can't use jquery's delegate,live,bind since i have no event, i need to add that class when my ajax call get a specific response.
asmon is offline   Reply With Quote
Old 07-14-2011, 09:55 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
This one line doesn’t tell us anything. Please show us more. Also, if you add the element dynamically within an AJAX function or whatever, it is probably within that function that you need to add the class.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 07-14-2011, 10:07 PM   PM User | #3
asmon
New Coder

 
Join Date: Apr 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
asmon is an unknown quantity at this point
More code won't help here.
$("#tabs [room_id='"+msg_room+"']")
is selecting an element which has been added dynamically using ajax, and
I am guessing that's why addclass doesn't work, and that's my problem.

I have an addition ajax script running each second, when a response triggers
that function, i need to execute that code, so i can't use
$("#rooms").delegate('li','click', function() {....
because i am not clicknig anything or any other event to trigger it.
asmon is offline   Reply With Quote
Old 07-14-2011, 10:15 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by asmon View Post
More code won't help here.
I’m sorry, but how can you determine what helps and what doesn’t? After all, it’s you who wants help from us. If you don’t care to provide any more information even if someone asks for it how can you expect any helpful reply? Am I speaking with myself when I say we need more code? Or do you expect me to use my magic psychic power to read your mind?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:02 AM.


Advertisement
Log in to turn off these ads.