Get... vs. Query...
What is better to use (or more efficient) and why? (Supposing you want just one element returned) document.getElementById() document.getElementsByClassName() Or document.querySelector()
","upvoteCount":1},{"@type":"Answer","text":"Thanks everyone for your answers. I also spent some time looking around online. It looks like there's some other issues with using `query` methods. There are compatibility issues. Also slower as mentioned. I have yet to understand the \"live list\" issue as @mike choy mentioned. I also struggle a little to see what kind of situation that is relevant. \r\n\r\nAnyway, I've settled that I will use `get` methods most of the time.\r\nIf I need to find something very specific with css selectors then `query` methods will be very good. (i.e. document.querySelector('.chicken feet'))","upvoteCount":1},{"@type":"Answer","text":"@Mike I found out how this works. If anyone wants to see:\r\n\r\nhttps://jsfiddle.net/dcookdesign/h28ab89a/21/","upvoteCount":1}]} }
What is better to use (or more efficient) and why? (Supposing you want just one element returned) document.getElementById() document.getElementsByClassName() Or document.querySelector()