user316389
user316389

Reputation: 87

how to add text at end of html tag using javascript

I have a dropdown selection tag as

    <select id="_users_add_dropDown" class="form-control style-scope view-work-organizer" style="width: 100% !important; bottom: 0;" required="">
  <option value="View" class="style-scope view-work-organizer" selected="">
                        VIEW</option>
                  <option value="Edit" class="style-scope view-work-organizer">
                EDIT</option>
         <option> </option></select>

I want to add at end of <select id="_users_add_dropDown" class="form-control style-scope view-work-organizer" style="width: 100% !important; bottom: 0;" required="">

into

`<select id="_users_add_dropDown" class="form-control style-scope view-work-organizer" style="width: 100% !important; bottom: 0;" required="" onclick=alert('test');>`

I want to do using JavaScript. I tried

var x = document.getElementById("_users_add_dropDown");
        var option = document.createElement('option');
option.text = "alert('1'); </script>
";
 x.add(option);

This is not what i want as it add alert('1') as drop-down option I want it to appear at end of html tag. thanks.

Upvotes: 0

Views: 249

Answers (1)

Marc Salvetti
Marc Salvetti

Reputation: 362

you are asking to add an attribute to the html element, so you should not use the createElement method.

have you tried this ?

    document.getElementById("_users_add_dropDown").setAttribute('onclick', "alert('test')");

Upvotes: 1

Related Questions