themistral Posted October 15, 2010 Share Posted October 15, 2010 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 More sharing options...
themistral Posted October 15, 2010 Author Share Posted October 15, 2010 OK sorted it! The problem was as I thought, so changed the name of the class in the stylesheet to be more specific to the element I needed to add the class name to. Link to comment https://forums.phpfreaks.com/topic/215929-jquery-addclass-not-working/#findComment-1122423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.