.getElementsByTagName function unable to disable dynamically created JavaScript buttons

I am currently attempting to deactivate buttons that have been generated in JavaScript...

var upButton = document.createElement('button');
var  downButton= document.createElement('button');
var deleteButton = document.createElement('button');

At this point, I am trying to select all the buttons but it is not functioning as expected...

function play() {
  var buttons = document.getElementsByTagName("button");
  buttons.disabled = true;
  buttons.style.backgroundColor = "#DADAD9";
}

The function is being executed and operates, however, the deactivation part is not. Can anyone provide assistance? Thank you!

Answer №1

querySelectorAll retrieves multiple elements, so a loop is required to work through each result.

function activate() {
    var images = document.querySelectorAll("img");

    for (i = 0; i < images.length; i++) {
        images[i].disabled = true;
        images[i].style.border = "1px solid #333";
    }
}

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

Harnessing $in Variables

I defined a request variable, but I can't seem to use it in the $in block: { $lookup: { from: 'users', as: 'user', let: { "blogIds": "$blog.id" }, pipeline: [{ $project: { ...

Facing unexpected behavior with rxjs merge in angular5

import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/merge'; this.data = this.itemsCollection.valueChanges() this.foo = this.afs.collection<Item>('products') .doc('G2loKLqNQJUQIsDmzSNahlopOyk ...

What is the most effective way to determine when the browser is in offline mode?

My web application features several Ajax components that refresh periodically within a dashboard-style page. I am looking to implement a feature where, in the absence of Internet connection, the content on the page remains static and displays a message in ...

An unexpected JavaScript error has occurred in the main process: TypeError - not enough arguments provided

During my attempt to package an electron project using the electron-packager npm module, I encountered an error when running the .exe file of the packaged product. The error specifically references app/dist/packaged-app-win32-x64... and you can see the err ...

What are some strategies for improving search efficiency in arrays containing over 50,000 elements?

I am working with a large array of strings containing about 50,000 elements. export const companies = [ "000014", "000016", "000017", "000019", "000020", "000021", "000023" ...

Meteor does not come with build packages included

I am currently working on creating native versions of a small meteor application that I developed. Running them on iOS or Android using the meteor run command is successful, and using meteor build with --debug generates an ipa/apk that functions properly. ...

The jQuery library triggers an error that can only be resolved by refreshing the

I am currently experiencing an issue with my form (form links are provided below, specifically referring to form1). The problem arises when I include jquery.js, as it fails to load the doAjax and getIP functions that are contained in a separate js file nam ...

Ways to store a filestream coming from Node.js into AngularJS

When using my express server, I have a post-request set up to retrieve a pdf file from Amazon S3 and then send it back to Angular. This is the endpoint in my express server: var fileStream = s3.getObject(options).createReadStream(); fileStream.pipe(res); ...

Customize Cell Styling with Bootstrap Full Calendar CSS

I am attempting to implement a Bootstrap calendar feature where cells are colored green if the timestamp is greater than today's date. This can be achieved by: $checkTime > $today cell.css = green background I came across this code snippet on St ...

Is there a Syntax Issue Preventing the Jquery Accordion from Working in IE7?

I have developed a website that utilizes jquery accordion along with some basic functions to control the accordion via external navigation links. While testing it in different browsers, everything seems to be working fine except for IE7. In IE7, the accord ...

Learn how to extract an ID created with AngularJS using JavaScript

I have a piece of code that generates multiple divs using ng-repeat and assigns each one an id based on a specific value. <div ng-repeat="item in $scope.items"> <div id="ajs-{{item.title}}">{{text}}</div> <script> v ...

What is the best way to expand ui-router states within Angular 11?

In my Angular 2+ project, I've defined a state using ui-router with Ng2StateDeclaration for the configuration. export const myState:Ng2StateDeclaration{ name:"myState", url:"mystate" component: "myComponent", para ...

Returning to the previous state in AngularJS when unchecking a checkbox

I'm a beginner when it comes to using angularjs HTML File: <div class='col-md-2 searchdisplay-col1' ng-controller="amenitiesController" style="margin-top:20px"> <h4>Amenities</h4> <label ng-repeat="facilityName ...

Exploring asynchronous data handling in AngularJS using promises

Currently, I am working on a single page application using angularJS and encountering some difficulties in storing asynchronous data. In simple terms, I have a service that contains my data models which are returned as promises (as they can be updated asy ...

Save an HTML5 canvas element as a picture using JavaScript and specify the file extension

Is there a way to save an Html5 canvas element as an image file using Javascript? I've tried using the CanvasToImage library, but it doesn't seem to work for this purpose. You can view my current code on JsFiddle. <div id="canvas_container" ...

Save a PHP variable following a JavaScript (or any other language) redirection

I am attempting to accomplish the following task: A parent element (referred to as A) should be the only means of accessing an iframe within another application (known as B) on the same domain. It is important that direct access to B is restricted, with a ...

Guide on implementing a live media stream using JavaScript

I am looking to set up a live audio stream from one device to a node server, which can then distribute that live feed to multiple front ends. After thorough research, I have hit a roadblock and hope someone out there can provide guidance. I have successf ...

Choose the checkboxes you want to include and pass them along as parameters for action execution

Looking for a way to execute a mass delete function on a list of items? Each item is equipped with a checkbox, and there's a designated button to remove all selected items. Sounds like a job for Symfony! The challenge here lies in the fact that the l ...

Analyzing data visualization within CSS styling

I have the desire to create something similar to this, but I am unsure of where to start. Although I have a concept in mind, I am struggling to make it functional and visually appealing. <div id="data"> <div id="men" class="shape"></di ...

How to properly fill state values for testing components with React Testing Library?

Introducing my custom component -> export default() => { const [list, setList] = useState([]) const handleAddToList = () => { // Executes an API call and updates the list state. setList(response); } return ( <div> ...