I searched for a while but couldn't find anything useful.I have the following css
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 10px;
background-image: url('http://www.w3schools.com/html/smiley.png'),
-webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #fefefe),
color-stop(0.49, #dddddd),
color-stop(0.51, #d1d1d1),
color-stop(1, #a1a1a1)
);
background-size:20px;
background-repeat: no-repeat;
}
Now I want to change the background image to some other image src by the help of jquery or plain javascript which I can test from chrome console.So that I have something like:
`background-image: url('http://someotherimage/test.png'),`
Could anyone please mention the correct syntax. Thanking you in anticipation of favorable response.
I have a little hack way to help you.
Here I have write a same selector as
input[type="range"]::-webkit-slider-thumb
in a<style>
tag, and append it to the last of<head>
.And then, this style will cover the
background-image
you ever write.jsFiddle Code
I have updated my anwser as T.J.
There is now a CSS3 way of doing this which I think is much simpler and cleaner.
In your HTML tag you define a
style
tag such as:style="--img-path:url('/images/small_blue_inner.svg') no-repeat 8px 8px #fff;"
In your CSS stylesheet your background would then read:
background:var(--img-path);
You can then set your style attribute with jquery the way you normally would:
$(slider).attr('style',"--img-path:url('/images/small_ALT_Img.svg') no-repeat 8px 8px #fff;--img-border:1px solid #11b6d1");
And as you can use these in pseudo elements I believe this is the best solution for 2018.
I am posting solution which worked for me for anyone facing the same issue.As I wanted to change the css of the -webkit-slider-thumb on the fly so I did something like this I used a class for the input and added css for this class like this
I also added the other set of css under a different class name like this
Then using Jquery I changed the classes whenever I needed to change the css, i.e if I remove the
first_class
and addsecond_class
to the input it will change the image of the -webkit-slider-thumb Thankyou for all those who tried to help.