Reputation: 655
I'm trying to add an extra attribute to new Option()
so that I can pass the value to href
.
for(var i =0; i < response.data.length; i++)
{
pages[i] = new Option(response.data[i].name,response.data[i].access_token);
}
right now the option looks like this
<option value ="access_token">name</option>
the final result should look more like this
<option value ="access_token" data-id="id">name</option>
then with a second script I collect the values and pass to an href
var access_token = e.options[e.selectedIndex].value;
var link = "next_page.php?access_token=" + access_token;
var element = document.createElement("a");
element.setAttribute("href", link);
right now href looks like this
<a href="next_page.php?access_token=access_token"></a>
The href end result should grab new attribute
<a href="next_page.php?access_token=access_token&data_attribute=data"></a>
Upvotes: 0
Views: 306
Reputation: 3917
(pages[i] = new Option('_name_','_value_')).dataset['id'] = '_id_';
This will work in FF, but unfortunately doesn't allow chainning. Hope this helps.
Upvotes: 2