Jump to content

Jquery addClass not working


themistral

Recommended Posts

Hi guys,

 

I'm having an interesting problem

 

I have the following code doesn't work.

 

$("#title").focus(function () {
$("#d_title").addClass("active");
});

 

Bus this code does:

 

$("#title").focus(function () {
$("#d_title").css("background", "#f39c12");
});

 

I was wondering if anyone could offer some advice as to why the second one works and the first one doesn't.

 

If I change the first example to:

 

$("#title").focus(function () {
$(this).addClass("active");
});

 

it works but it changes #title and I need #d_title to have the class added - so I know it's not a problem with the css stylesheet not being imported.

 

I'm wondering if it's the order in which the css is being applied...

Any help gratefully appreciated!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.