Try the attr function.
$('#input').attr("value", "Value");
$('#input').attr("name", "Name");
$('#input').attr("myOwnAttribute", "Something");
Question
I'm new in using phonegap and I have some problems.
I've created a webbased application which is running pretty nice in the browser (also on android). Now I want to port it to a phonegap-application. It was a little bit tricky to get the mainpage running - there are only a few lines of javascript, but it works.
At this time I've just one input on the mainpage, just a textinput. I found to change the value by using:
$('#input').val('Value');
But now i want to set some other attributes. In javascript i used:
var input = document.getElementById('input');
input.setAttribute("value", "Value");
input.setAttribute("name", "Name");
input.setAttribute("myOwnAttribute", "Something");
When I try this in phonegap I'll get the error
Object #<HTMLDocument> has not method 'getElementById'
If I try
$('#input').setAttribute("value", "Value");
I'll get the error
Object has not method 'setAttribute'
So why is this not working? How can I set any attribute of any object?
Thanks a lot
Markus
Solution
Try the attr function.
$('#input').attr("value", "Value");
$('#input').attr("name", "Name");
$('#input').attr("myOwnAttribute", "Something");