Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Quotes in HTML attribute value in UI Issues of WEB UI Tips and Tricks
2294 Views
How to add special characters in html attribute values? 
Special characters making problem while adding with attribute values in HTML.

Double quotes - "
Single quotes - '
And operators - &
Lessthan operator - <

Characters should get encoded in attribute value.

Example: Wrong value
<div data="example"data">Data</div>

Should use
<div data="example&quot;data">Data</div>
Function to do encode
function encodeHTML(s) {
    return s.split('&').join('&amp;')
                  .split('<').join('&lt;')
                  .split('"').join('&quot;')
                  .split("'").join('&#39;');
}
Previous Topics
Previous lessons of current book.
Best Lessons of "WEB UI Tips and Tricks"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details