Sometimes we want to get the name of a tag, for example:<div>a</div> get "div". Take a look at the following example:
There is a class= "a" on the page, possibly input, or a normal div or span tag, now we want to add a value to this tag "value1". If it is input, set its Value property to Value1,div to set its innerhtml to value1. How to achieve it ...
If the pure JS is implemented as follows:
Find the code for this tab. This represents the tag object found
if (this.localname== "Input" | | this.localname== "textarea") {
this.value= "value1"
}else{
this.innerhtml= "value1";
}
Use jquery to implement the following:
if ($ (this) [0].tagname== "Input" | | $ (this) [0].tagname== ' textarea ') {
$ (this). Val (valueout);
} else{
$ (this). html (valueout);
But there is a problem is that the name of the label returned by IE is uppercase, so it is safe to write a function that ignores the case for equality of judgment:
var equalsignorecase=function (str1, str2) {
if ( Str1.touppercase () = = Str2.touppercase ()) {return
true;
}
return false;
if (Equalsignorecase (this) [0].tagname, "input") | | Equalsignorecase ($ (this) [0].tagname, textarea)] {
$ (this). Val (valueout);
} else{
$ (this). html (valueout);
The above is small series for everyone to get the element of JS to achieve the full content of the label name, I hope that we support cloud Habitat Community ~