4
iRobot
7y

document.getElementById() makes me cringe :/

Comments
  • 1
    Please recommend a NATIVE alternative to it
  • 1
    @RazorSh4rk I'm referring in the context of JS framework ! If you are using Angular Js ..You don't need it. Just ng-model value wud do. Please look at the tags
  • 1
    @Vikram oh that creates context and it's so different
  • 0
    QuerySelector ftw
  • 1
    document.GetElementsByClassName("uniqueClassName").First();

    I shit you not, this turned up about 500 times in a website project I was lucky enough to inherit
  • 2
    function id(i){
    return document.getElementById(i);
    }

    Problem solved ✔
  • 2
    function $(element) {
    return document.querySelector(element);
    }
  • 1
    @Vikram So its better to do angular.element('#id') then? 🙃
Add Comment