Solarpitch Posted October 13, 2011 Share Posted October 13, 2011 Hey Guys, I have a div with a data attribute of id. I can get the value fine ("278715"). How can I add a class to this div using jQuery. <div class="ppc_result" data-id="278715"></div> Here's what I'm trying but doesnt seem to work. $("data-id").val(videoData['id']).addClass('ppc_thumb_playing'); Quote Link to comment https://forums.phpfreaks.com/topic/249035-adding-css-with-jquery/ Share on other sites More sharing options...
Zane Posted October 13, 2011 Share Posted October 13, 2011 Since data-id is an attribute you have to select it as one $("div[data-id]").val(videoData['id']).addClass('ppc_thumb_playing'); Quote Link to comment https://forums.phpfreaks.com/topic/249035-adding-css-with-jquery/#findComment-1278983 Share on other sites More sharing options...
Solarpitch Posted October 13, 2011 Author Share Posted October 13, 2011 Ah right, It's sorta working now, the only thing is it applies the class to all of the ppc_result div's.. I just want to apply the class to that div with the specific data-id.. Quote Link to comment https://forums.phpfreaks.com/topic/249035-adding-css-with-jquery/#findComment-1278986 Share on other sites More sharing options...
Solarpitch Posted October 13, 2011 Author Share Posted October 13, 2011 figured it out.// $(".ppc_thumb[data-id=" + dataID + "]").addClass('ppc_thumb_playing'); Quote Link to comment https://forums.phpfreaks.com/topic/249035-adding-css-with-jquery/#findComment-1279008 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.