Javascript get id

function check(id){
    var _id = document.getElementById(id);
    url = "test.php?check=1&id=" + _id;
}

      

I want the ID in the url to work, but without the ID that is in the check ('123');

This is for innerHTML to load something

hope you can help me with getting id

Hello

+1


a source to share


2 answers


The function document.getElementId()

returns the value of an object based on the ID string that you supply; so if your page has an element with id foo

, then you call

document.getElementById("foo");

      

to return an object for that element so you can manipulate it (changing styles or attributes, etc.).

If you want to embed the id in the url of the test.php page, why not just pass the id string of the element you pass using the function ?:



function check(id){
    url = "test.php?check=1&id=" + id;
}

      

Then call

check("123");

      

will set the variable url

totest.php?check=1&id=123

+4


a source


var _id = document.getElementById(id).id;

      



+2


a source







All Articles