JavaScript match vs trim

Both the match and the trim can be used as a substitute to string.contains() since JavaScript does not contain the property contains, however they work in different ways:

Match

docomunet.getElementById(‘myId’).textContent.match(‘stringToLookFor’);   // FireFox:  looks for the content ‘stringToLookFor’ in ‘myId’ text and returns true or false

docomunet.getElementById(‘myId’).innerText.match(‘stringToLookFor’);   // Chrome/IE:  looks for the content ‘stringToLookFor’ in ‘myId’ text and returns true or false

Trim

docomunet.getElementById(‘myId’).textContent.trim(‘stringToLookFor’);   // FireFox:  trims the text in myId to ‘stringToLookFor’ and is returned as string /var

docomunet.getElementById(‘myId’).innerText.trim(‘stringToLookFor’);   // Chrome/IE:   trims the text in myId to ‘stringToLookFor’ and is returned as string /var

Continue reading

JavaScript innerText property for Firefox (textContent)

The JavaScript commonly used innerText property functions well in chrome and internet explorer, however in firefox it has a different naming property called textContent:

document.getElementById(‘sample’).innerText = ‘NOT for firefox’;     //Chrome/IE

document.getElementById(‘sample’).textContent= ‘FOR firefox’;  //Firefox