3

I'm implementing a prerequisite graph using Cytoscape.js. But the problem is, when I set the id with the course name, (for example: Beginning Programming), I can't properly select the node because of the blank space in the course name.

temp.group = "nodes";
temp.data = {id: a, label: b}; // A: "Beginning Programming" B: "1111"
cy.add(temp);

Then, when I do this:

cy.$("Beginning Programming");

It says it is an invalid selector.

Is there a way of doing so?

Moved
  • 130
  • 8

2 Answers2

1

After few hours of researching, I found that attribute selector works. The following code works like a charm.

cy.$("[id='Beginning Programming']");
Moved
  • 130
  • 8
0

You cannot use spaces in the id (see Can a DOM element have an ID that contains a space?).

I'd recommend replacing the space with underscore like this

var modifiedId = a.split(' ').join('_');
temp.data = {id: modifiedId , label: b}; // A: "Beginning_Programming" B: "1111"

If the id is also displayed, you could replace it with %20 (which is displayed as a space in html)

Community
  • 1
  • 1
Ed Ballot
  • 3,405
  • 1
  • 17
  • 24
  • Replacing the space with underscore is another solution, but I use the id as the label too. It means I need another attribute to put the course name. – Moved Jul 05 '15 at 00:11