0

I haven't found a good example of this, I have this CSS snippet.

#divname .jqplot-point-label {
     color: #000000;
}

I know how to change CSS if it's just the ID, or just the class, but in this case I'm not sure what the JavaScript would look like.

I'm trying

$('#divname .jqplot-point-label').css({'color':'#000000'});

But that didn't work.

Thanks!

7
  • 3
    Can you post some of your HTML? The code you provided there should work. Commented Jun 25, 2012 at 18:33
  • 1
    there is nothing wrong with the code, are you sure jquery has been loaded? Commented Jun 25, 2012 at 18:34
  • Your code works, I tested it : jsfiddle.net/dystroy/a9EU2 Commented Jun 25, 2012 at 18:36
  • 2
    is your jQuery invoked in $(document).ready(function(){ //code});? Commented Jun 25, 2012 at 18:36
  • 1
    try running alert($('#divname .jqplot-point-label').length) in firebug or chrome console (whichever u r using). If the returned value is 0 then either path given is wrong or you are running this code before the element(s) getting added to the DOM Commented Jun 25, 2012 at 18:49

2 Answers 2

1

Make sure to wrap your code in ready handler (your code is fine but missing to use ready handler will cause your code not to work):

$(function(){
  $('#divname .jqplot-point-label').css({'color':'#000000'});
});

I assume you are including jQuery in your page with correct path.

2
  • I don't seem to be getting inside the $(function() {} it skips it. Commented Jun 25, 2012 at 19:07
  • @Jason: You should create an example at jsfiddle or jsbin Commented Jun 25, 2012 at 19:08
-1

use $('#divname.jqplot-point-label') as the selector. (no space between the id and class name).

$(#divname .jqplot) is looking for an element with class .jqplot with an ancestor of #divname.

3
  • he didn't say that he wants to change the CSS of an element with id and class given in question so we need to assume that his selector is working for him as his CSS style selector Commented Jun 25, 2012 at 18:50
  • I'm trying that now, the color doesn't change. This is set before jqplot is called. Initially it's set in the style block to #ffffff, which works fine. I want to change it if certain criteria are met. Yes, jQuery is referenced and works fine with other functions. I'm not sure if it needs to be invoked or not, I use other functions before this one. Also I'm using jQuery Mobile for some things. Commented Jun 25, 2012 at 18:55
  • @sv_in you are correct. He didn't say that he was trying to call an id an a class name. I described what each did in the answer. I should have added a comment instead of an answer. Point taken. Commented Jun 25, 2012 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.