skip to Main Content

  issue when in html attribute

Code first. <div data-a="a b" data-b="a&nbsp;b" id="test"></div> <div data-a="a<b" data-b="a&lt;b" id="test2"></div> var test1= document.getElementById('test'); var test1_a= test.getAttribute('data-a'); var test1_b=test.getAttribute('data-b'); // data-a="a b" data-b="a&nbsp;b" console.log('1:',test1_a===test1_b); // got false; var test2= document.getElementById('test2'); var test2_a= test2.getAttribute('data-a'); var test2_b=test2.getAttribute('data-b'); // data-a="a<b" data-b="a&lt;b" console.log('2:',test2_a===test2_b); //…

VIEW QUESTION
Back To Top
Search