Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Compare innerText to a string constant

Posted on 2014-10-30
5
Medium Priority
?
123 Views
Last Modified: 2014-11-18
How do I compare innerText to a string constant?  

var REQUIRED = "** Required **"

var theclass = document.getElementById("<%= FK_classification.ClientID %>");
alert(theclass.innerText);

I want to in effect do: Is  theclass.innerText equal to "** Required **"
0
Comment
Question by:HLRosenberger
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40414245
var theclass = document.getElementById("<%= FK_classification.ClientID %>");
theText  = theclass.textContent = theclass.innerText

if(theText!=REQUIRED){
  //different
}

Open in new window

0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40414271
theText  = theclass.textContent = theclass.innerText

What does this statement do?  double assignment?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40414277
It's for cross browser support

Actually on double checking innerText seems supported by Firefox now but best to keep it for older browsers.
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40414291
And I screwed up there it should be
theText  = theclass.innerText || theclass.textContent 

Open in new window

0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40450246
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question