JSFiddle - React, Tailwind, and code Playground
HTML
<!-- TYPE -->
<span class="checkbox">
<input id="id1" type="checkbox" name="id1">
<label for="id1"> check me</label>
</span>
<textarea cols="40" rows="10" id="id2" type="text" name="id2"></textarea>
<h4>
Checkbox
</h4>
<p class="result"></p>
<p class="test"></p>
<h4>
Textarea
</h4>
<p class="result2"></p>
<p class="test2"></p>
CSS
*{margin:0; padding:0;}
h4{
margin-top:20px;
}
JavaScript
// TYPE
var type = $('#id1').attr('type');
$('.result').append("type: ", type);
// Type checking
if (type == "checkbox") {
$('.test').append("[1] yes found one <br/>");
}
else{
$('.test').append("[1] ahw I found an error");
}
// This will fail because case sensitive
if (type == "Checkbox") {
$('.test').append("[2] yes found one");
}
else{
$('.test').append("[2] ahw I found an error");
}
// TAGNAME
var tagname = $('#id2')[0].nodeName;
$('.result2').append("tagname: ", tagname);
// tagName checking
if (tagname == "TEXTAREA") {
$('.test2').append("[1] yes found one <br/>");
}
else{
$('.test2').append("[1] ahw I found an error");
}
// This will fail because case sensitive
if (tagname == "textarea") {
$('.test2').append("[2] yes found one");
}
else{
$('.test2').append("[2] ahw I found an error");
}