0

I'm writing HTML in Java using a servlet and I'm having a problem where scrolling over a DOM object (third party, jqplot) will light up the text for a particular list. I have HTML (declared before the jQuery):

<li id='cap_1'>
  <span>DOG</span>
</li>

And the following code later:

out.println("<script>$('#chart2').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) { var x = 'cap_'+pointIndex; alert(x); $(x).css(\"display\",\"none\"); } );</script>");

The alert is triggering and returns correctly (cap_1). But the CSS isn't working (i've tried display, background-color, color, etc - nothing worked).

What am I missing? jQuery and library declarations are confirmed and the bind is part of the jqplot library.

user2124871
  • 803
  • 3
  • 9
  • 25

3 Answers3

1

You need to add # symbol before x.

$('#' + x).css(... and so on

Or, where you declare x:

... var x = '#cap_' + ...
Vlad
  • 2,475
  • 21
  • 32
1

You are missing the '#' selector:

out.println("<script>
               $('#chart2').bind('jqplotDataHighlight', 
                                  function (ev, seriesIndex, pointIndex, data) { 
                                      var x = '#cap_'+pointIndex; //<-- Here
                                      alert(x); 
                                      $(x).css(\"display\",\"none\"); 
                                  });
            </script>");
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
0

You are missing the DOG selector:

out.println("<script>$('#chart2').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) { var x = 'li:contains(DOG)'; $(x).css(\"display\",\"none\"); } );</script>");
redolent
  • 4,159
  • 5
  • 37
  • 47