html - Detect line break in text with javascript -
html - Detect line break in text with javascript -
i'm able set line break javascript in element, can't read them.
example:
<div id="text"></div>
js:
document.getelementbyid("text").innerhtml = "hello <br /> world"; var x = document.getelementbyid("text").innerhtml; if(x == "hello <br /> world") { alert('match'); }
there no match in case...
it pretty much never thing .innerhtml
property object , seek compare exact string. because contract browser has homecoming equivalent html, not exact same html. may not problem if there no nested dom elements in requesting, can problem if there nested html elements.
for example, versions of ie alter order of attributes, alter quoting, alter spacing, etc...
instead, should either search actual dom want or smaller piece of html know can't alter or utilize search algorithm tolerate of changes in html.
as niels mentioned in comment, chrome, ie11 , firefox homecoming "hello <br> world"
can see simple debugging statement this:
console.log("'" + x + "'");
working demo see shows: http://jsfiddle.net/jfriend00/zc59x2bl/
fyi, code contains error. need pass document.getelementbyid()
string document.getelementbyid("test")
, not document.getelementbyid(test)
.
javascript html dom
Comments
Post a Comment