javascript - object doesn't support this property or method document.querySelector -


i'm testing 1 line code on ie7 it's giving me following error:

object doesn't support property or method , refers to

here's problem line in question:

var checked = document.queryselector('[name="answer1"]:checked'); 

this whole code

question1 : did training?

<input name="q4" value="yes" type="radio"> yes <input name="q4" value="no" type="radio"> no <br> <button id="getval">cick here</button>  <script type="text/javascript">  document.getelementbyid('getval').onclick = function() {     var checked = document.queryselector('[name="q4"]:checked');     alert(checked ? checked.value : 'not selected'); } </script> 

is there anyway fix that?

queryselector only available in ie8+. query selector in ie7 you'll need sizzle, standalone version of css query-by-selector code that's built jquery. or if prefer bit lighter , more seamless use polyfill such 1 described here, so:

if (!document.queryselectorall) {   document.queryselectorall = function (selectors) {     var style = document.createelement('style'), elements = [], element;     document.documentelement.firstchild.appendchild(style);     document._qsa = [];      style.stylesheet.csstext = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';     window.scrollby(0, 0);     style.parentnode.removechild(style);      while (document._qsa.length) {       element = document._qsa.shift();       element.style.removeattribute('x-qsa');       elements.push(element);     }     document._qsa = null;     return elements;   }; }  if (!document.queryselector) {   document.queryselector = function (selectors) {     var elements = document.queryselectorall(selectors);     return (elements.length) ? elements[0] : null;   }; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -