This question already has answers here:
How can I write 'a:hover' in inline CSS?
(24 answers)
Closed 9 months ago.
How can I use a:hover in inline CSS inside the HTML style attribute
like this but doesn't work
<div
style={{
"&:hover": {
background: "#efefef"
},
}} >
</div>
You can do this way.
a:hover {
background-color: yellow;
}
See the full answer here. https://codepen.io/charp95/pen/LYQxZrm
<a href="mypage.html"
onMouseOver="this.style.color='#FFF'"
onMouseOut="this.style.color='#000'" >Whatever you have to display</a>
You can try this, using onMouseOver and onMouseOut, this gives the same effect but it's not efficient for many elements.
Related
This question already has answers here:
How to get an HTML element's style values in JavaScript?
(5 answers)
Closed 6 years ago.
I have a simple script that is getting the color of the text in an element and printing it to the console. However, when I run the script, I'm getting an empty string rather than the actual color. Can anyone explain to me why and how to fix it?
HTML
<div id="scrollingTextHolder">
<p id="scrollingText">Hello</p>
</div>
CSS
#scrollingText{
margin-top: 5%;
color: black;
}
JS
window.addEventListener("load", function(){
console.log(document.getElementById("scrollingText").style.color);
})
Pen
You can use getComputedStyle() and getPropertyValue(), also color is returned as rgb(R,G,B)
var a = document.getElementById("scrollingText");
console.log(window.getComputedStyle(a).getPropertyValue('color'))
#scrollingText {
margin-top: 5%;
color: black;
}
<div id="scrollingTextHolder">
<p id="scrollingText">Hello</p>
</div>
This question already has answers here:
jquery to change style attribute of a div class
(9 answers)
Closed 7 years ago.
I want to change background color of my div using jQuery selector and I can't get it to work.
My Codepen.
HTML
<div class='demo'></div>
CSS
.demo {
height: 100px;
width: 100px;
}
JS
$(document).ready(function() {
$('demo').style.backgroundColor = "black";
});
$('demo') will return jquery object not a dom object also your selector is missing a ., use
$('.demo').css('background-color ','black');
Reference: jquery css() doc.
This question already has answers here:
Selecting and manipulating CSS pseudo-elements such as ::before and ::after using javascript (or jQuery)
(26 answers)
Closed 7 years ago.
So I have this CSS query here:
last-ns > .col-2:first-child > a::before {
content: "";
border-left: 1px solid #aaa;
position: absolute;
height: 448px;
left: 5px;
}
I want to use jQuery to adjust the height value of that specific a::before element; however, I have no idea how to grab that using jQuery...
I'm used to the typical jQuery form of changing CSS:
$("p").css ({
"background-color": "yellow", "font-size": "200%"
});
But I am unsure how to change more complex CSS queries such as my last-ns > .col-2:first-child > a::before.
Any idea how to do this? Any help is appreciated. Thanks.
edit
My overall goal is to extend the height of that element when a separate element is clicked.
Dunno if this helps you, but... instead of manipulating styles in jQuery add custom class to DOM and move your changes to css.
JS:
$('.last-ns > .col-2:first-child > a').addClass('foo');
CSS:
.last-ns > .col-2:first-child > a.foo::before {
border-color: red;
}
Simple example in jsFiddle: http://jsfiddle.net/3v5zbpqm/
This question already has answers here:
How do I simulate a mouseover in pure JavaScript that activates the CSS ":hover"?
(6 answers)
Closed 7 years ago.
CSS's "hovered state" will trigger when the user hovers over an element:
<style>
.element{
}
.element:hover{
background-color:red;
}
</style>
How can we set the element to "hovered state" using Javascript?
Is it possible?
You're probably better off duplicating the :hover styles into another class and then just adding that class name to the element when you want them to change permanently. Pseudo-classes are "pseudo" for a reason.
If you could accept using :focus instead of hover, you can use:
var links = document.getElementsByTagName('a');
links[0].focus();
JS Fiddle demo.
Or
var linkToFocus = document.getElementById('link');
linkToFocus.focus();
JS Fiddle demo.
This approach, obviously, requires adapting your CSS to include the a:focus style:
a:link, a:visited {
background-color: #fff;
}
a:hover, a:focus, a:active {
background-color: #f00;
}
This question already has answers here:
Animate element transform rotate
(7 answers)
Closed 8 years ago.
What is wrong with this Code?
$("button").click(function(){
var div=$("#oarm2");
div.animate({marginTop:'150px', transform:'skew(15deg, -60deg)'},"slow");
});
When I press the button, an div Element should be go down in the Page and change the Form.
The "marginTop" is functionally, but the transform skew not..
What is wrong? How I must write this?
Check this Demo Fiddle
Js
$("#go").click(function(){
$("#oarm2").animate({marginTop:'150px', transform:'skew(15deg, -60deg)'},"slow"); });
HTML
<button id="go">ยป Run</button>
<div id="oarm2">Hello!</div>
CSS
div {
background-color: #bca;
width: 100px;
border: 1px solid green;
}
Here I include jquery library file jquery-1.8.3.js