4
I got the following snippet spinning pretty:
function busca() {
var str = document.getElementById('txt').value;
if(document.getElementById(str))
console.log(str + ' existe.');
else
console.log(str + ' ñ existe');
}
<input type="text" id="txt"><input type="button" value="mais" onclick="busca()">
<pre>Ex.: vaca, boi, porco ou galinha</pre>
<div id='vaca'></div>
<div id='boi'></div>
<div id='porco'></div>
<div id='galinha'></div>
Now I intend to address some more details ...
Suppose there are others in the HTML document id
segmented like this:
id='vaca-leiteira'
id='boi-nelore'
id='Porco_granja'
id='gaLinha_caIpirA'
Note that we have your designation followed by a hyphenate or underline, and having some variations between "vowels" and "consonants" being capital letters and/or lowercase.
How can I resolve this when typing in the text field? Type:
dairy cow
country hen
Note that I do not use hyphenate and/or underline, and put some vowel or consonant in capital letters and/or lowercase outside the scope of identification, all on purpose. I still want the right result.
In everything the riddle is, ignore these points and bring the final result. Would have to make use of some
RegExp
?
Wait, you want to treat random letters and symbols ? {@#$#@%#@%@#&} ?
– Philip Developer
Ah yes, I understand the question now, really need treatment
– Philip Developer