JavaScript javascript takes too long to perform, Makes viewers wait too long javascript takes long time load,javascript window.open takes long

function change(element) {
  document.getElementById('imageReplace').src = element;
}

function change_1() {
  document.getElementById('1').style.background = '#111';
  document.getElementById('1').style.color = '#FFF';
  document.getElementById('1').style.cursor = 'auto';
  document.getElementById('2').style.background = '#FFC300';
  document.getElementById('2').style.color = '#FFF';
  document.getElementById('2').style.cursor = 'pointer';
  document.getElementById('3').style.background = '#FFC300';
  document.getElementById('3').style.color = '#FFF';
  document.getElementById('3').style.cursor = 'pointer';
}

function change_2() {
  document.getElementById('2').style.background = '#111';
  document.getElementById('2').style.color = '#FFF';
  document.getElementById('2').style.cursor = 'auto';
  document.getElementById('1').style.background = '#FFC300';
  document.getElementById('1').style.color = '#FFF';
  document.getElementById('1').style.cursor = 'pointer';
  document.getElementById('3').style.background = '#FFC300';
  document.getElementById('3').style.color = '#FFF';
  document.getElementById('3').style.cursor = 'pointer';
}

function change_3() {
  document.getElementById('3').style.background = '#111';
  document.getElementById('3').style.color = '#FFF';
  document.getElementById('3').style.cursor = 'auto';
  document.getElementById('1').style.background = '#FFC300';
  document.getElementById('1').style.color = '#FFF';
  document.getElementById('1').style.cursor = 'pointer';
  document.getElementById('2').style.background = '#FFC300';
  document.getElementById('2').style.color = '#FFF';
  document.getElementById('2').style.cursor = 'pointer';
}
.row_1 {
  float: left;
}
<div class="row_1">
  <button id="1" onclick="change('somepic.jpg'); change_1()">1</button>
  <button id="2" onclick="change('somepic2.jpg'); change_2()">2</button>
  <button id="3" onclick="change('somepic3.jpg'); change_3()">3</button>
 </div>
Answer:1

Don't repeatedly use document.getElementById(). It makes no sense. Every time you do this, you're searching the DOM for the node.

So instead of this:

function change_3() {
  document.getElementById('3').style.background = '#111',
  document.getElementById('3').style.color = '#FFF',
  document.getElementById('3').style.cursor = 'auto'
}

do this

var three = document.getElementById('3');

function change_3() {
  three.style.background = '#111',
  three.style.color = '#FFF',
  three.style.cursor = 'auto'
}
Answer:2

I'm using Lodash to format a string like DIGITAL & TECHNOLOGY into Digital & Technology. I've tried with the following code: _.startCase(_.lowerCase('DIGITAL & TECHNOLOGY')); However, ...

I'm using Lodash to format a string like DIGITAL & TECHNOLOGY into Digital & Technology. I've tried with the following code: _.startCase(_.lowerCase('DIGITAL & TECHNOLOGY')); However, ...

  1. format strings with python
  2. format strings with printf
  3. format strings in c
  4. format strings in java
  5. format strings in javascript
  6. format strings in python 3
  7. format strings in r
  8. format strings in golang
  9. format strings in excel
  10. format strings python 3
  11. format strings in powershell
  12. format strings in matlab
  13. format strings in ruby
  14. format strings in swift
  15. format strings in js
  16. format strings in php
  17. format strings in sql
  18. format strings in python 2
  19. format strings in scala
  20. format strings in vb.net

I have an angularJS directive, which has it's templateUrl property set to a function, that determines which template to use based on a service function. When the service finishes a certain job (which ...

I have an angularJS directive, which has it's templateUrl property set to a function, that determines which template to use based on a service function. When the service finishes a certain job (which ...

  1. angularjs directive with parameters
  2. angularjs directive with controller
  3. angularjs directive with template
  4. angularjs directive with ng-model
  5. angularjs directive with typescript
  6. angularjs directive with controller and link
  7. angularjs directive with attribute
  8. angularjs directive with html template
  9. angularjs directive with scope
  10. angularjs directive with templateurl
  11. angularjs directive with input
  12. angularjs directive with dynamic template
  13. angularjs directive with params
  14. angularjs directive with arguments
  15. angularjs directive with service
  16. angularjs directive with controller example
  17. angularjs directive with value
  18. angularjs directive with css
  19. angularjs directive with ng-repeat
  20. angularjs directive with function

I am trying to make a web app work on tablets. I don't actually need the guesture stuff from the tablets, just the equivelent of mousedown mouseup and mousemove. However, the touch events seem to ...

I am trying to make a web app work on tablets. I don't actually need the guesture stuff from the tablets, just the equivelent of mousedown mouseup and mousemove. However, the touch events seem to ...

  1. touch events jquery mobile device
  2. touch events jquery
  3. touch events jquery mobile
  4. touch events jquery library
  5. touch listener jquery
  6. iphone touch events jquery
  7. ios touch events jquery
  8. touch screen events jquery
  9. safari touch events jquery
  10. canvas touch events jquery
  11. javascript touch events jquery
  12. simulate touch events jquery
  13. mouse touch events jquery
  14. touch event listener jquery
  15. jquery touch events without jquery mobile
  16. jquery touch events w3schools
  17. jquery touch events plugin
  18. jquery touch events swipe
  19. jquery touch events example
  20. jquery touch events demo

I have a component with a login form. What I need to do is to get it to reload the page / route after the user clicks the submit button. The reason for this is that after the submit button is ...

I have a component with a login form. What I need to do is to get it to reload the page / route after the user clicks the submit button. The reason for this is that after the submit button is ...

  1. reload page router angular
  2. reload router page
  3. reload page react router
  4. reload page vue router
  5. reload page react router dom
  6. reload page ui router
  7. reload page using router in angular
  8. angular 4 reload page router