views:

143

answers:

4
+2  Q: 

JQuery attributes

Hi, the following is my HTML DOM element...

<input type="text" style="width: 200px;" id="input1"/>

I want to keep the date value in it..But somewhere i need to specify that it is going to hold date value in the Dom element..

How can i do so..Please suggest me

A: 

What does it display instead?

It could be that date is a non standard form type. I think it is coming in HTML 5, but currently it is not supported.

Could you accidentally have 2 elements with that Id ? That code looks like it should work.

Try this

$("#input1").css( {border: '1px solid red'} );

To ensure it is matching the right element. If the correct element doesn't gain a red border, then your selector is probably incorrect.

alex
+1  A: 

According to w3c standard there are no input controls with "date" type. Check it on W3C Forms in HTML documents

zdmytriv
+3  A: 

JQuery is returning the runtime type of the input element from the DOM. Since "date" isn't a valid type for a form input, it is returning the default value : "text".

These are the valid input types:

* "text"
* "password"
* "checkbox"
* "radio"
* "submit"
* "reset"

If you try the same code snippet with one of the above instead of "date", it works fine.

Darren Hicks
+2  A: 

Looks like you are trying to hide data inside the control.
An easier way would be to assign a css class to the element.

and jquery has lots of methods for retrieving the class names out of an element.

Or you could go with the html 5 standard for adding data like this:

<input id='ctrl' type='text' data-attr='date' />

Then you can retrieve the attribute value like this:

var value = $("#ctrl").attr("data-attr");
Chris Brandsma