edit the first option name

后端 未结 2 1240
感情败类
感情败类 2021-01-19 02:54

I have the following code which I do not have access to.

What I want to do is add some text into the first option which is now empty. Text such as \"Select Address\

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-19 03:39

    $("select[name=My_Saved_Billing] option:first").text("Select Address");
    

    Demo: http://jsfiddle.net/VGhdX/

    To answer your side question from your comment (if I understand correctly):

    how would automatically select the first option that had a value or option text whichever is easier to code

    You can do this using the Has Attribute Selector:

    $("select[name=My_Saved_Billing] option[value]:first").text("Foo");
    

    The Has Attribute selector will ignore present attributes which contain empty values (so value="" will not match).

提交回复
热议问题