KTM
KTM

Reputation: 868

Catch name of element using jquery

I have a form select element with name field_p_payment[value] and i need to catch this element and reset the select box , i used the following code ,

document.getElementsByName("field_p_payment[value]").selectedIndex='0'

But it doesnt seem worked , i also tried the jquery version as

$('[name="field_p_payment[value]"]').attr("selectedIndex","0");

But $('[name="field_p_payment[value]"]').prop("selectedIndex","0"); works .

But i cant use prop because am using an oldest version of jquery .Any solution ?

Upvotes: 2

Views: 262

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Usually getElementsByName returns the results in a HTML collection. So try,

document.getElementsByName("field_p_payment[value]")[0].selectedIndex='0'

Also read here for more information.

Upvotes: 3

Related Questions