how to replicate jquery functions in javascript $(), Hide()

Asked

Viewed 43 times

3

To create a site, simple in javascript more would like to automate the selection elements, and a function to hide/show the elements. But I end up getting error. But I don’t understand why.

To select the elements I’m using

function $(par){
    return document.querySelector(par)
}

and to hide:

function hide(e){
    return e.style.display = 'none';
}

the declaration shall remain:

$('.header').hide()

only that I am returned the error:

Uncaught TypeError: $(...).hide is not a function
  • It seems that you are not calling jquery on your page. Of course, you should call before calling your js script.

  • Ah idea and redo these two functions of jquery in pure javascript

1 answer

5


  • Thank you, it worked! I will search now on prototype. To understand how it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.