Search code examples
jquerydimple.js

JQuery: addClass() is not working despite correct selection


I have been looking at this for too long, and imagine this is something simple, but can't seem to find the solution.

I have added a bar chart to a div using dimple.js, and I am trying to change the class of one of the bars based on a dropdown selection.

I have a variable that holds the selection, and it works correctly. I can log the value in the console, and it shows the correct object. However the class never gets added.

Any help would be appreciated.

  var barClass = 'rect.dimple-' + selectedHospital.split(' ').join('-').toLowerCase();
  console.log($(barClass));
  $(barClass).addClass('addedClass')

result of the console.log();

[rect#dimple-all--hospital-1--, prevObject: n.fn.init(1), context: document, selector: "rect.dimple-hospital-1"]

Solution

  • I was able to solve this by changing to using JQuery v3.2.1 (was using v2.1.1). From what I have read, prior to this version classes cannot be added to elements within an SVG.