I want to know if we can select an element by using its id and class at the same time. I know in css we can do that with #x.y, but but how can it be accomplished in javascript? I tried the following code and it worked fine but then all the controls with ui-slider-handle class got affected(which is obvious). I think I need a combination of id and class both so that only that particular element will be affected.
Javascript:
$(".ui-slider-handle").text(ui.value);
You will never need to do this since the ID is unique; if you know it, you can already identify the element.
Your problem is actually that your selector matches too many elements. There are other ways to limit the “range” of a selector:
Add a parent element with a certain ID/class:
.parent .ui-slider-handlematches only elements with the classui-slider-handlethat are children of all elements with the classparentYou can also limit by parent type:
div .ui-slider-handleOr only direct children:
div > .ui-slider-handleSee jQuery selectors for all the goodies.