The attached script was created for the geojson file I created that works properly.

     $(document).ready(function() {
      $(pz).click(function() {

My question is how can I hide the displayed layer with the click feature?

I would like to ask you some help to create the script.

(I use mapbox.js not mapbox-gl.js)

2 Answers 2


My JavaScript is not that good, but instead of click look at https://api.jquery.com/toggle/

and then map.remove(); if needed depending on how $.toggle works.

PS: jquery could be added to your tags


Here is an official Mapbox examples which shows how to toggle layers using onclick:


  • Thank you, I try this example, but it does not work for something. The displayable layer can be retrieved from a dropdown / semantic menu ... it may be the problem ... Apr 26, 2018 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.