Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

set multiple attributes javascript

// create a helper function
function setAttributes(el, attrs) {
  for(var key in attrs) {
    el.setAttribute(key, attrs[key]);
  }
}

// call like this
setAttributes(elem, {"src": "http://example.com/something.jpeg", "height": "100%", ...});
Comment

DOM element add multiple attributes

function setAttributes(element, attributes) {
  Object.keys(attributes).forEach(attr => {
    element.setAttribute(attr, attributes[attr]);
  });
}

const attributes = {
  name: 'example',
  title: 'Box 1',
  disabled: '',
  style: 'background-color: salmon; color: white;',
};

const button = document.getElementById('btn');
setAttributes(button, attributes);
Comment

how to apply multiple attributes using js

Object.assign(element,{...attributes})
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript query corrector 
Javascript :: second level relationships data not found in strapi 
Javascript :: javascript Big decimal 
Javascript :: javascript variable without value 
Javascript :: Nodemailer Reuseable Code 
Javascript :: apostrophe issue in javascript 
Javascript :: parentsuntil without jquery 
Javascript :: JavaScript querySelector - Group selector 
Javascript :: Flutter retrieve data from Json url 
Javascript :: how to produce null in accessing array function in javascript 
Javascript :: Finding the longest word in a string 
Javascript :: function directory javascript 
Javascript :: angular interpolation check if value is null 
Javascript :: why typescript is superset of javascript 
Javascript :: godot get sibling node 
Javascript :: getelementsbyclassname angular 
Javascript :: protoypes in constructor functions in javascript 
Javascript :: get size of json array online 
Javascript :: response conditions 
Javascript :: how to print 1 to n numbers without using loop javascript 
Javascript :: react weather app 
Javascript :: Default function arguments in ES6 
Javascript :: what does react js allows us to do 
Javascript :: react-navigation: Detect when screen, tabbar is activated / appear / focus / blur 
Javascript :: nodejs express mongodb boilerplate 
Javascript :: js plugin for drop down with images 
Javascript :: Safe Area View for android / Removing overflow of screen for android 
Javascript :: Javacript code that delays, based on Milliseconds 
Javascript :: avascript-how-to-detect-if-a-word-is-highlighted 
Javascript :: refresh mathjax 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =