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";

Ah, cheers!

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.