Working with identifiers with spaces (Cytoscape.js)
I am using a preliminary graph using Cytoscape.js. But the problem is that when I set the ID with the course name (ex: Beginning Programming), I cannot select the node correctly because of the 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");
He says that this is an invalid selector.
Is there a way to do this?
+3
source to share
2 answers
You cannot use spaces in id (see Can a DOM Element have an ID containing a space? ).
I would recommend replacing the space with an underscore character like this
var modifiedId = a.split(' ').join('_');
temp.data = {id: modifiedId , label: b}; // A: "Beginning_Programming" B: "1111"
If the id also shows up, you can replace it with% 20 (which shows up as a space in the html)
0
source to share