0
var foo = 100;
        var firstCell = newRow.firstChild.innerHTML = "<button id='removeBtn' onclick='removeRow("+ foo +")'>X</button>";

I have this small line of code which inserts a button into a table cell then assigns it a function with a parameter (foo). Even though it works, my code editor, brackets, does not display the "+ foo +" part like the rest of the innerHTML. I think that it has to do with my quotation marks getting mixed up but I am not sure how to solve this problem. Would this be a problem or should I leave it like this?

  • What is `foo`? a string? – epascarello Feb 25 '16 at 21:38
  • Assuming it is working I can answer a bit here. Brackets is displaying it differently because it is trying to help you distinguish between the predetermined string and the variable portion of the string. It is a visual cue as to where there is a change of format for you. – Anthony Rivas Feb 25 '16 at 21:44

1 Answers1

0

You can escape double quotes so you have have them inside the onclick.

... =  "<button id='removeBtn' onclick='removeRow(\""+ foo +"\")'>X</button>";
epascarello
  • 204,599
  • 20
  • 195
  • 236