logo
Tags down

shadow

Applying a Javascript function to multiple buttons?


By : Kyosuke Takayama
Date : July 30 2020, 07:00 PM
hop of those help? The id must be unique in the whole document. You can use class or different attribute to select multiple nodes.
code :
// listener function
function handle_button_click() {
  console.log(this.innerText);
}

// add click events using `class`
const buttons = document.querySelectorAll('.button');
for (const button of buttons) {
  button.addEventListener('click', handle_button_click, false);
}
<button class="button">Button 1</button>
<button class="button">Button 2</button>
function handle_button_click() {
  const popups = document.querySelectorAll('.popup');
  const buttons = document.querySelectorAll('.button');

  popups.forEach(p => p.classList.remove('open'));
  buttons.forEach(b => b.classList.remove('active'));

  const popup = document.querySelector(this.dataset.popup);
  if (!popup) return;

  popup.classList.add('open');
  this.classList.add('active');
}

const buttons = document.querySelectorAll('.button');
for (const button of buttons) {
  button.addEventListener('click', handle_button_click, false);
}
.popup {
  display: none;
}

.open {
  display: block;
}

.active {
  color: cadetblue;
}
<button class="button" data-popup="#popup1">Button 1</button>
<button class="button" data-popup="#popup2">Button 2</button>

<div class="popup" id="popup1">Popup 1</div>
<div class="popup" id="popup2">Popup 2</div>


Share : facebook icon twitter icon

WP7 Applying Style to Multiple Buttons


By : Møhãmmėď Alĥàķímë
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , If it is just above code it should work fine, but if you set any of your buttons to be disabled (IsEnabled = false), it will fail as in the disabled state of your style, a storyboard is looking for an element named DisabledVisualElement to animate,
code :
<VisualState x:Name="Disabled"> 
  <Storyboard> 
    <DoubleAnimation Duration="0" Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="1"/> 
  </Storyboard> 
</VisualState>

Applying 1 JavaScript syntax for Multiple Buttons


By : JorgeAyala
Date : March 29 2020, 07:55 AM
Hope this helps class is a reserved word in javascript. Change the variable name to something valid and select multiple elements by separating them with a comma:
code :
var $class = $('.dvData, .dvData1');
<table  class="dvData">
    <tr>
        <th>Account System</th>
        <th>Market Code</th>
        <th>Payment Amount</th>
    </tr>
    <tr>
        <td>RED</td>
        <td>222</td>
        <td>$103.00</td>
    </tr>
    <tr>
        <td>BLUE</td>
        <td>111</td>
        <td>$13.00</td>
    </tr>
    <tr>
        <td>GREEN</td>
        <td>555</td>
        <td>$143.00</td>  
    </tr>
</table>
<br />
<input type="button" class="toExcelButton" data-target="dvData" id="btnExport" value="Export" onclick="TableToExcel();" /> 

<table  class="dvData1">
 <tr>
    <th>Billing System</th>
    <th>Market Code</th>
    <th>Payment Amount</th>
</tr>
<tr>
    <td>RED</td>
    <td>222</td>
    <td>$103.00</td>
</tr>
<tr>
    <td>BLUE</td>
    <td>111</td>
    <td>$13.00</td>
</tr>
<tr>
    <td>GREEN</td>
    <td>555</td>
    <td>$143.00</td>  
</tr>
</table>
<br />
<input type="button" class="toExcelButton" data-target="dvData1" id="btnExport" value="Export" onclick="TableToExcel();" />
$(document).ready(function() {

    $(".toExcelButton").click(function() {
        var table = $("." + $(this).data('target'));
        var strCopy = $('<div></div>').html(table.clone()).html(); window.clipboardData.setData("Text", strCopy);
        var objExcel = new ActiveXObject("Excel.Application");
        objExcel.visible = false; 
         var objWorkbook = objExcel.Workbooks.Add; 
        var objWorksheet = objWorkbook.Worksheets(1); 
        objWorksheet.Paste; 
        objExcel.visible = true;
    });

});

javascript function on multiple buttons


By : BHASKAR G
Date : March 29 2020, 07:55 AM
help you fix your problem Usually, when you write inline event handler you may take advantage of:
this: current element: When code is called from an in–line on-event handler, its this is set to the DOM element on which the listener is placed: event: event element object
code :
onclick="setColor('button', '#101010')"
onclick="setColor(this, event, '#101010')"
function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? 'rgb(' +
        parseInt(result[1], 16) + ', ' +
        parseInt(result[2], 16) + ', ' +
        parseInt(result[3], 16) + ')'
     : null;
}


function setColor(btnEle, evt, color) {
    if (btnEle.style.backgroundColor == hexToRgb("#E68352")) {
        btnEle.style.backgroundColor = "#FFFFFF"
    }
    else {
        btnEle.style.backgroundColor = "#E68352"
    }
}
<input type="button" id="button1" value = "A-D" style= "color:black" onclick="setColor(this, event, '#101010')";/>
<input type="button" id="button2" value = "E-H" style= "color:black" onclick="setColor(this, event, '#101010')";/>
<input type="button" id="button3" value = "E-H" style= "color:black" onclick="setColor(this, event, '#101010')";/>

Applying a function to all buttons?


By : Waleed Shaikh
Date : March 29 2020, 07:55 AM
it should still fix some issue event.target.tagName results are capitalized.
A BUTTON TEXTAREA etc.

Multiple JavaScript Buttons Simplified Into One Function


By : naveen
Date : March 29 2020, 07:55 AM
help you fix your problem I have three buttons and three JS functions that toggle the display of three different divs. How can I simplify/condense my three JS functions into one function that connects each button to its corresponding content? , Add a parameter to the condensed function et violà!
code :
function myFunction(id) {
  var x = document.getElementById(id);
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
<button onclick="myFunction('ContentOne')">Button 1</button>
<button onclick="myFunction('ContentTwo')">Button 2</button>
<button onclick="myFunction('ContentThree')">Button 3</button>

<div id="ContentOne">This is Content One.</div>
<div id="ContentTwo">This is Content Two.</div>
<div id="ContentThree">This is Content Three.</div>
Related Posts Related Posts :
  • Why doesn't the .remove() method also affect the variable it's being set on?
  • React hooks error: Rendered more hooks than during the previous render
  • How to create a completely new Keyword in JavaScript?
  • When summing values from 2 arrays how can I cap the value in the new array?
  • A pop up window to login in
  • How to push spacebar action to array
  • How do i highlight a specific table row depending on the url
  • Truly Weak Reference Event Emitter / Dispatcher: is it possible?
  • Conditionally render a a background image based on current view using React Router
  • Can not retrieve component template while routing
  • How to keep the checkbox status after refreshing the page
  • Array of Object - divide information as per values in it
  • Calculating body style height (for horizontal scroll) in javascript not working
  • How to exclude certain values from randomly generated array
  • Change colour of selected <li>
  • Formatting date object in an Array with moment is giving an unexpected result
  • combineLatest operator alternative
  • 'object' is never reassigned. Use 'const' instead
  • What does the spread operator in ES6 convert to in older JavaScript? Is it costlier than array.concat?
  • Get duplicates in array of strings and count number of duplicates
  • How to fix React Redux and React Hook useEffect has a missing dependency: 'dispatch'
  • Call a ajax request only if there are ajax requests added to the list
  • Using the jQuery each function to count divs with the same class
  • FInding out the Harshad number
  • angular route is not working and not changing current view
  • Callback executed before function finishes execution
  • How to create subfolder and document on Firestore web?
  • Scroll algorithm -- improving fetch and display of data
  • New To Programming World
  • Using mongorestore to insert many documents into a temp collection
  • How to extend localStorage across devices (without DB)
  • How to do pre increment without using ++I?
  • Retrieve filterViewId from batchUpdate request addFilterView
  • What is the corresponding instanceof target for text nodes?
  • How to Test the API by Token on Postman?
  • How to set Bootstrap dropdown menu on hover?
  • In Slate.js editor.apply(operation) is not applying "split_node" operations correctly
  • No data in GET response
  • Javascript using if else to determine array value
  • Error when I run npm install Error: 404 Not Found: 7zip-bin@~4.1.0
  • I want to modified my JSON output using JS
  • Error in Entry module not found and in webpack
  • Submit button is not submitting the form after changing the button type
  • Why is the function created is not working.?
  • How can I do day timer with javascript?
  • Tap screen to trigger autofocus with getUserMedia
  • Unable to bind html table data to mvc controller Model
  • How can I simply work around a missing JS property in an object in an object?
  • How to add anything at a specific position in a string using vanilla javascript
  • using async methods inside of array.map() in javascript
  • Math.random() vs random() in Khan Academy Computer Programming
  • Call two functions with onPress in react native
  • Use a global variable inside promise javascript
  • Turn array of objects into array of properties
  • Would having a Pure Class concept make sense or not?
  • Why catch invoked with success promise?
  • Match whole word if it meets a condition
  • Inserting items into array with bracket syntax doesnt affect length?
  • adding value inside an input - React
  • How does setInterval() run independently of sequential execution?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org