Javascript test if div has text in it
2 answers
If you are using jQuery, you can do it like this:
if($.trim($('#div_Msg').text()) != "") {
// Code here
}
In simple JavaScript, do the following:
if(document.getElementById("div_Msg").innerHTML.replace(/^\s*/, "").replace(/\s*$/, "") != "") {
// Code here
}
Both cases get the text and trim the spaces from the beginning and end of the line, and then compare them with the empty line.
+7