The visibility property allows to get an element value.
I am sharing a simple code here that shows how easily you can get
a element value & text using JavaScript.
Get element value by id
|
<div><input id="firstname" type="text" value="c-sharphub" /></div>
$(function() {
var firstname = document.getElementById("firstname").value;
alert(firstname);
});
or
function GetFirstName(){
var firstname = document.getElementById("firstname").value;
alert(firstname);
}
|
Get element value by class
|
<div><input id="firstname" type="text" value="c-sharphub" /></div>
$(function() {
var firstname = document.getElementsByClassName("firstname").value;
alert(firstname);
});
or
function GetFirstName(){
var firstname = document.getElementsByClassName("firstname").value;
alert(firstname);
}
|
Get element text by id
|
<div><span id="spanText">c-sharphub</span> </div>
$(function() {
var spanText = document.getElementById("spanText").innerHTML;
alert(spanText);
});
or
function GetspanText(){
var spanText = document.getElementById("spanText").innerHTML;
alert(spanText);
}
|
Get element text by class
|
<div><span id="spanText">c-sharphub</span> </div>
$(function() {
var spanText = document.getElementsByClassName("spanText").innerHTML;
alert(spanText);
});
or
function GetspanText(){
var spanText = document.getElementsByClassName("spanText").innerHTML;
alert(spanText);
}
|