This content applies to a previous version of CARTO
In October 2021 we released a new version of our platform. You can find the latest documentation at docs.carto.com
Back to Help Center
How can I open a popup when clicking on a button with CARTO.js?
Overview
The provided example demonstrates opening a CARTO.js popup upon clicking an HTML element like a button. The approach involves three key components:
- Data Retrieval: Uses the SQL API with Axios to fetch coordinates and thematic information
- Popup Display: Leverages Leaflet popup functionality to present the retrieved data
- User Interaction: Binds the popup action to button click events
Implementation Method
This simple example shows how to open a CARTO.js popup when clicking on an HTML element such as a button by querying geographic data and displaying it in a Leaflet popup with the retrieved content.
Note: This content references previous CARTO products. For current documentation, visit docs.carto.com.
