Reputation: 4696
Is there an easy way to do this in one line
( node.innerText || node.textContent ) = text
// node = DOM node
// text = string
Obviously the above does not work.
Upvotes: 1
Views: 130
Reputation: 3171
One could do it like this:
node['textContent' in node? 'textContent' : 'innerText'] = text
Upvotes: 2
Reputation: 788
Use JQuery to shorten your syntax
use .text() method
so your code will be
if($(selector).text() = text){
// your code here
}
Upvotes: 0
Reputation:
Just use node.innerText = node.textContent = text
, which is harmless.
Upvotes: 2
Reputation: 16961
First, not-so-compact attempt
node.innerText ? node.innerText = text : node.textContent = text
Upvotes: 1