How do i go about emptying the values of textboxes here is below code i h’ve worked out but doesn’t seem to work
var txtName = $("input#txtName"),txtPrice = $("input#txtPrice");
First Method
$(txtName,txtPrice).val("");
- this is actually wrong because the price textbox would now become the context to search within i suppose.
Second Method
$([txtName,txtPrice]).val("");
- I don’t understand why i should do this as they are already jQuery Objects(But works)
I Put them in variables as these are used further in the script.
Here is a few ways to do it;
(There is a
$sign in yourtxtPriceinput by the way.)First Method didn’t work because it’s a way of using jQuery selector. When you use jQuery like that first parameter will be the selector and second will be the container object where the selector works. Basically it’s almost same thing like this;
Because there is no
txtNameintxtPriceneither value will be emptied.Second Method works because you’re giving your parameters as an array to jQuery selector. It accepts it and does
.val()action to every element of array. This way is legit but because your variables already jQuery objects there is no need to use this.