views:

620

answers:

3

I'm quite fresh on jQuery, and I've just implemented jQuery + jQuery UI, but on the datepicker widget it seems like the classes added on the inputs from before are removed, and datepicker classes are added insteady.

How can I keep my classes as well?

A: 

It shouldn't delete your classes but append. You just make sure that you don't do that (removing classes) by mistake. Also a code would help me more to understand your problem.

Wbdvlpr
A: 

It doesn't remove existing classes (provided you didn't name the same as what jQuery UI uses). But it does wrap the tag with additional tags. So your original input field is a level or two deeper in the DOM tree than before. It is something to be aware of if you rely on jQuery methods like parent() or sibling() as they are now at a different level.

Agent_9191
Are you sure it wraps it and pushes it deeper? In my answer above, the code suggests it only adds classes, it doesn't affect the parent/child depth of the input field.
Chris
My mistake. Working with too many of the elements of jQueryUI and got them mixed up.
Agent_9191
A: 

Note that datepicker will add its own unique id that looks something like this id="dp124326451455" for each input field that has datepicker attached to it. For this reason, your <input > should not already have an id (which I know you don't, you have a class).

In addition to that strange looking id it adds to each field, it also adds a class called hasDatepicker. But as Wbdvlpr said, it just appends it to any existing classes you may have. Mine for example has 2 classes myclass and myclasssec and looks like this in php

<input name="myinputfield" class="myclass myclasssec" type="text" />

so it gets turned to:

<input id="dp1243264511551" name="myinputfield" class="myclass myclasssec hasDatepicker" type="text">

Notice that the only 2 changes tht happened are the new id as I said (id="dp124326451455") and the new class that gets "appended" to the end of the other classes: class="myclass myclasssec hasDatepicker"

Hope it helps you. But if you need other help you probably need to post your source to make easy for us to help you better.

Chris