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
https://forums.phpfreaks.com/topic/215929-jquery-addclass-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.