Skip to content Skip to sidebar Skip to footer

How Do I Get Html Tag Value (div) In Javascript

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 or No < DI

Solution 1:

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.

Solution 2:

First, no space between < and div (saw here: < DIV id="phone_valid" class="popup-value"></DIV>' )

Second:

functioncheckSubmit(){
var country=$("#phone_valid").text(); // it is a div not input to get val().if(country=="No")
{
    alert("Not a valid number");
    returnfalse;
}

Solution 3:

You probably want to do this:

$("#phone_valid").html();

or

$("#phone_valid").text();

Solution 4:

you can use this:

document.getElementById("phone_valid").innerHTML;

Solution 5:

.val() is for form elements. You should use .text() or .html() to get the value from a DIV.

HTML

<DIVid="phone_valid"class="popup-value"></DIV>

JavaScript

functioncheckSubmit(){
    var country=$("#phone_valid").html();
    if(country=="No")
    {
        alert("Not a valid number");
        returnfalse;
    }
}

Hope this helps!

Post a Comment for "How Do I Get Html Tag Value (div) In Javascript"