Solved

Compare innerText to a string constant

Posted on 2014-10-30
5
98 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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now