I am trying to write a javascript function with an if statement that will execute a command if the text between the two tags matches. I could write a lot of βifβ statements in which the command is executed when the value in the input text field is equal to the value of the criteria of the βifβ expression, for example:
function Test() { if (document.getElementById('A').value == 1) { alert('test'); } } <input type="button" id="B" onCLick="Test()"/> <input type="text" id="A"/>
When I enter "1" in the text box and click the button, a warning window will appear. The problem I am facing is that I would like to do the same with text containing two tags. For instance:
function Test() { if (document.getElementById('A').value == 1) { alert('test'); } } <input type="button" id="B" onCLick="Test()"/> <p id="A">1</p>
In my project, I would use words instead of numbers, so I understand that I will have to surround the word in quotation marks. Unfortunately this does not work. Is it possible to write an "if" statement, as described above, which determines whether the text between two tags is true? In addition, I tried document.getElementById ('A'). Text and document.getElementById ('A'). InnerHTML, but none of them made a difference. I even tried using one equal sign instead of two; however, this will make all criteria true, regardless of whether they were true or not.
thanks
DFM
Dfm
source share