Having trouble with clicking a button in HTML?

I'm facing an issue with a button on my HTML page that features a background created using the popular particle library. The button is visible but not clickable. I've attempted adjusting the background size and alignment without success. How can I resolve this and make the button clickable?

Here's my code:
HTML:

<div id="particles-js" ><canvas class="particles-js-canvas" width="500" height="1000"></canvas></div>

<button type="button" class="btn btn-info" onclick="alert('hello')">Info</button>

CSS:

body {
    background: #212121;
}

.particles-js-canvas{
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0px;
  right: 0px;
}

And the Javascript code to initialize the particles:

$(window).on('load', function() {

    particlesJS("particles-js", {
        "particles": {
            // Particle settings
        },
        "interactivity": {
            // Interactivity settings
        },
        "retina_detect": true
    });
});

Answer №1

Just because your button is visible, it doesn't necessarily mean it's in the forefront. In reality, the canvas may be covering up your button. To address this, consider adding a z-index to the background:

body {
    background: #212121;
}

.particles-js-canvas{
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0px;
  right: 0px;
  z-index: -1;
}

Answer №2

It seems like this is the solution you are looking for.

<button type="button" class="btn btn-primary" onclick="alert('Greetings'); setLocation('https://sample.com');">Click me</button>

Answer №3

One issue is arising due to the canvas being placed within a div element. The canvas is obstructing the button and acting as a barrier on top of it.

By inserting the following CSS snippet, this problem can be resolved:

canvas{
  z-index:-1;
} 

Answer №4

To display a message box, use javascript before your alert function. It's important to avoid using inline javascript and instead create a separate function. Also, be cautious not to use 'alert' as a function name since it's a reserved method in the window object.

<div id="particles-js">
  <canvas class="particles-js-canvas" width="100" height="100"></canvas>
</div>

<button type="button" class="btn btn-info" onclick="javascript:alert('hello')">Info</button>

Answer №5

We have implemented a particles.js canvas as an overlay element. Adjusting the z-index order in this situation does not have any impact. If the interactive features such as 'grab, repulse, bubbles' in particles.js are not needed – It is feasible to deactivate pointer events on the canvas using CSS. This allows users to click through the canvas and interact with the underlying elements.

canvas.particles-js-canvas-el {
    pointer-events: none;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with Javascript's JSON.stringify or PHP's json_decode?

I am attempting to send an array from JavaScript to PHP. JavaScript: var json = JSON.stringify(extraFields); url += "&json="+json; PHP: $json = json_decode($_GET['json'], true); foreach($json as $K=>$V){ echo "json".$K . "=" . $V ...

Is it possible to refresh the JSViews data that is underneath using an onclick event?

I have created a photo gallery using a JSViews template which includes upvote and downvote buttons. When these buttons are clicked, it triggers a database update to increase the score. However, I am facing an issue with updating the Score field in the HTML ...

Trouble with CSS Positioning: Resizing my browser causes my image to shift in position

Upon resizing the browser window, my website layout adjusts accordingly and looks as intended at a smaller size: However, as I begin to expand the browser width, the centrally positioned image starts shifting towards the left. I aim for the image to remai ...

Displaying information stored in a database as notifications in the notification icon within the HTML/PHP header

Within my MySQL database, there exists a table named order_detail. This table is populated with values from my android app. I am looking to display the order_id as a notification in my admin panel, which is built using HTML/PHP. The attributes of the orde ...

Name the Angular interpolation function with the (click) event

I have a JSON file that defines different dynamic buttons, but when I click on them, the function is not being called. Here's how my JSON file looks: export const liveButtonData = [ { title: 'My Name', function: 'getName()'} ...

What methods can I employ to utilize the name attribute for POST requests instead of the ID attribute in TinyMCE?

My inline TinyMCE form sends content to qry.php with the key "edit_me". I prefer the default behavior of sending content using the name attribute instead. <script type="text/javascript"> tinymce.init({ selector: '#edit_me', ...

Enhancing OpenAI API Responses with WebSocket Streaming through Express Middleware Integration

  Currently, I am in the process of developing an Express.js application that requires integration of OpenAI's streaming API responses to be transmitted in real-time to a front-end via WebSockets. Even though I have established communication between ...

What is the best way to prevent event propagation in d3 with TypeScript?

When working with JavaScript, I often use the following code to prevent event propagation when dragging something. var drag = d3.behavior.drag() .origin(function(d) { return d; }) .on('dragstart', function(e) { d3.event.sourceEvent ...

Individual User's Time Slot

Greetings! I am in the process of developing a web application where users can seek assistance for their problems: One challenge I am facing is how to inform users of the time a question was posted in their specific time zones. For instance, if I post a ...

What is the best way to implement Axios for data fetching in Gatsby's useStaticQuery function?

One way to fetch data in Gatsby is by using GraphQL, like in the following example: import { graphql, useStaticQuery } from "gatsby" const IndexPage = () => { const gatsbyRepoData = useStaticQuery(graphql` { github { repo ...

Utilizing jQuery to Sort Table Rows based on an Array of Class Names

I have a table containing values and a filter option where users can select multiple values to filter the table. I want to create a filter with numbers ranging from 1 to 10, and assign class names like filter_1, filter_2, filter_3, etc. to each table row ( ...

What is the best way to display jQuery/AJAX response in a table cell?

I am struggling with a script that retrieves data from a SQL database query and need help placing the result in a specific table cell. Here is the query: <script type="text/javascript"> $(document).ready(function(){ $('.typeval').change(f ...

Issues encountered when updating MySql Database from WordPress with Error 500, whereas the code functions properly when used outside of WordPress environment

Question: How can I update a MySQL database from within a JavaScript function on a WordPress WooCommerce page using Ajax? I have a working code snippet for updating the database, but when I integrate it into my WordPress page, I encounter a 500 error. To ...

The Vue.js component fails to display when included within another component

I am experiencing an issue with a menu item not displaying properly in my Vue.js application. The menu item should display the text "This is a menu item", but for some reason it is not being processed and rendered by Vue. These are the main com ...

Mysterious and never-ending loop that seems to loop endlessly and eludes my

My prototype includes a method for adding callbacks: /* * Add a callback function that is invoked on every element submitted and must return a data object. * May be used as well for transmitting static data. * * The callback function is supposed to e ...

embedding a button alongside the pager in an HTML document

I am encountering an issue with the positioning of a button in my paginated table setup. The button is currently displaying below the pager instead of being aligned on the left side of the page along with the pager. https://i.stack.imgur.com/gUiB9.png To ...

Implementing styling upon app mounting in Vue.js - a step-by-step guide

Hey, I'm working with a template code that looks like this: Here's my script code: data () { return { loadPage: true } }, mounted () { this.loadPage = true }, And here is my styling code: #app{ width: 100%; opacit ...

Looking to minify a JavaScript file? Consider changing the overly long variable name "veryLoooooooongVariable" to something shorter,

When working on improving readability, I tend to use very long variable names which can increase the size of my JS files. I'm wondering if there are any tools or libraries available that can automatically change these long names to shorter ones? I am ...

Concealing applicationId and clientToken in Datadog

I'm currently using an Angular application and I've integrated it with the Datadog application to utilize Session and Replay (RUM). However, I am concerned about the security of my sensitive information such as applicationId and clientToken. Is t ...

Troubleshooting permission problems with Yarn and node_modules in a Docker environment

I have a Docker container containing a Symfony 6 web application and various other services like php-fpm, node, and python. Additionally, I have separate containers for MySQL and Nginx, all running on Alpine 3.15. My current issue arises when I execute do ...