I have implemented this function (libphonenumber javascript )in a website http://www.phoneformat.com/
How do i get the value returned by this html tag. Whether Yes
The .val()
method is primarily used to get the values of form elements such as input
, select
and textarea
.
Use
$("#phone_valid").text();
to get DIV text content or
$("#phone_valid").html();
if you want markup.
you can use this:
document.getElementById("phone_valid").innerHTML;
You probably want to do this:
$("#phone_valid").html();
or
$("#phone_valid").text();
If you need to include HTML comments then consider using contents() method
$('#mydiv').contents()
Other wise html()
method or even text()
will be what you are looking for because val()
purpose is for form elements ;)
First, no space between <
and div
(saw here: < DIV id="phone_valid" class="popup-value"></DIV>'
)
Second:
function checkSubmit(){
var country=$("#phone_valid").text(); // it is a div not input to get val().
if(country=="No")
{
alert("Not a valid number");
return false;
}
.val() is for form elements. You should use .text() or .html() to get the value from a DIV
.
HTML
<DIV id="phone_valid" class="popup-value"></DIV>
JavaScript
function checkSubmit(){
var country=$("#phone_valid").html();
if(country=="No")
{
alert("Not a valid number");
return false;
}
}
Hope this helps!