简体   繁体   中英

Add a custom property to HTML element via Javascript

I am trying to add a custom element to Select html element.

 var sel=document.getElementById("sel1");
  sel.setAttribute("customprop","blabla");

In chrome it works, in IE8 it doesn't.

NO JQUERY

Check the question: Replace setAttribute with IE compatible script

It seems you need to add doctype on top of your page:

<!DOCTYPE html>

and then the following tag inside your head element to make setAttribute work:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM