The project I'm working on uses double quotes for strings in HTML and JavaScript by default.
This has been decided and there is nothing I can do about it.
What hasn't been decided however, is how we should deal with nested quotations.
There are three options I can think of:
- Begin with outermost quote & alternate.
element.innerHTML = "<a href='...'></a>";
<button onclick="alert('...')"></button>
- Begin with innermost quote & alternate.
element.innerHTML = '<a href="..."></a>';
<button onclick='alert("...")'></button>
- Escape everything.
element.innerHTML = "<a href=\"...\"></a>";
<button onclick="alert("...")"></button>
Which is the best practice in terms of overall convenience, style, safety, maintainability, portability, etc.? And please suggest a better way if there is other than the above.