skip to Main Content

I’m trying to move slider from site:
https://the-internet.herokuapp.com/horizontal_slider
with use of jQuery in Chrome devtools snippets but it does not work:

let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.crossOrigin = 'anonymous';
script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
document.head.appendChild(script);

jQuery.noConflict();

var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 39;

jQuery("input[type='range']").focus();
jQuery("input[type='range']").trigger(press);

2

Answers


  1. wrap your code in like

    script.onload = function() {
      jQuery.noConflict();
      jQuery(document).ready(function() {
        //your code goes here
      })
    }
    document.head.appendChild(script);
    
    Login or Signup to reply.
  2. Your code need a bit of correction.

    let script = document.createElement('script');
    script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
    script.crossOrigin = 'anonymous';
    script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
    document.head.appendChild(script);
    
    jQuery.noConflict();
    
    var press = jQuery.Event("keypress");
    press.ctrlKey = false;
    press.which = 39;
    
    // You selecting all the inputs with a type of range. this will return an array of elements so you can use a loop to iterate over all the elements or if there is a single element you use array indexing,
    
    jQuery("input[type='range']").focus(); 
    jQuery("input[type='range']").trigger(press);
    

    Updated Code -:

    let script = document.createElement('script');
    script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
    script.crossOrigin = 'anonymous';
    script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
    document.head.appendChild(script);
    
    jQuery.noConflict();
    
    // Selecting first element from the array
    let slider =  jQuery("input[type='range']")[0];
     
    // Use value to move the slider left or right;
    slider.value = 39;
    
    // Execute if you wish to change the value of the Span Element as well there is a predefined function
    showValue(39)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search