0

Hi all, just a quick question. I believed that $('#value') was a jQuery function equivalent to document.getElementById('value') however, in the code below, only the second function gives the desired result.

Can someone explain why this is?

        $('#value').value = "1";
        document.getElementById("value").value = "1";

Edited by James_43: format changes

3
Contributors
3
Replies
23
Views
1 Year
Discussion Span
Last Post by AleMonteiro
1

Just so you know:

$('#value') // jquery object
//set value as
$('#value').val(1);

$('#value')[0] // DOM object
// so you can also set the value as
$('#value')[0].value = "1"; // This is not recommended, it's just to show that jQuery objects relay on the DOM object itself
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.