Uncaught TypeError: Cannot read property 'setAttribute' of undefined at Object.onLoad Uncaught TypeError: Cannot read property 'setAttribute' of undefined at Object.onLoad javascript javascript

Uncaught TypeError: Cannot read property 'setAttribute' of undefined at Object.onLoad


We ran into the same error with the following html:

<select class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" role="button" v-model="selected" aria-haspopup="true" aria-expanded="false">    <option disabled value="">Please select one</option>    <option class="dropdown-item" value="type1">Carrier</option>    <option class="dropdown-item" value="type2">Shipper</option></select>

We tried removing data-toggle="dropdown" from the <select> tag; the error no longer occurred, and the dropdown menu still functioned. Not sure why this works, but it got rid of the error for us. Must be a conflict somehow? Anyways, if someone else is looking for a solution, this workaround may work for them.


I got this same error in Bootstrap 4.x because my dropdown menu did not have the same parent as the dropdown button I was using.

<span class="project-sort-by">Sort by: <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Recent</a></span><div class="dropdown-menu" aria-labelledby="dropdownMenuLink">    <a class="dropdown-item" href="#">Action</a>    <a class="dropdown-item" href="#">Another action</a>    <a class="dropdown-item" href="#">Something else here</a></div>