Javascript/jQuery - On hover over a li element, change class of another li element
Date : March 29 2020, 07:55 AM
I hope this helps you . The first thing you probably want to do is assign two different states/classes: active and current. One tells you which one should be shown, and the other actually toggles the visibility. $('#menu').on('mouseover', '> li', function(e) {
# attach hover event to the menu, and check which LI you are hovering
if (!$(this).hasClass('.current)')) {
$('.current', '#menu').removeClass('active');
}
}).on('mouseout', '> li', function (e) {
if (!$(this).hasClass('.current)')) {
$('.current', '#menu').addClass('active');
}
});
|
How to chain javascript to when hovering element to change picture of an element and display block third element
Date : March 29 2020, 07:55 AM
help you fix your problem You are using .hover() incorrectly. Hover takes two functions as parameters: the function to execute on mouseover and the function to execute on mouseout. For example: $(function() {
$('#my-id').hover(
// mouse over
function() {
$('#foo').show();
$('#bar').addClass('baz');
},
// mouse out
function() {
$('#foo').hide();
$('#bar').removeClass('baz');
});
});
|
Javascript: Replace Element vs Change Element Property
Date : March 29 2020, 07:55 AM
wish help you to fix your issue It is probably done this way to provide off-screen loading and for browser efficiency purposes (though the specific implementation is flawed in this regard). It seems likely that the lazy loading wants the actual loading of the image to happen "out of view". So, for that reason, a new Image object is created and the .src is set on that.
|
Change the color of a selected element if it is the correct element in javascript
Date : March 29 2020, 07:55 AM
around this issue I have a code I am writing to help my 6 year old kindergartner with her sight words that displays 3 different words from 3 different word arrays. I want to change the color of the word clicked if the word selected is a sight word to green and red if its one of the 2 that aren't. I'm not sure how to do this. Can anyone help?? , Here we go ^^ var sightWords = ["that", "as", "but", "it", "go", "and", "for", "me","do", "I", "we", "you", "can", "is", "have", "are", "was", "they", "in", "of"];
var words1 = ["cat", "dog", "rat", "hat", "log", "rug", "bed", "dot", "box", "leg", "bat", "cap", "cup", "bag", "net", "lid", "rip", "fun", "pot", "hug"];
var words2 = ["bar", "car", "gas", "set", "sit", "hit", "big", "let", "rag", "pen", "ball", "fall", "win", "hip", "pig", "lap", "hop", "mug", "hot", "hen"];
var num1 = Math.floor((Math.random() * 20) + 0);
var num2 = Math.floor((Math.random() * 3) + 1);
$("#question").html("Find the sight word.");
if (num2 == 1){
$("#words1").html(sightWords[num1]);
$("#words2").html(words1[num1]);
$("#words3").html(words2[num1]);
}
if (num2 == 2){
$("#words3").html(sightWords[num1]);
$("#words2").html(words1[num1]);
$("#words1").html(words2[num1]);
}
if (num2 == 3){
$("#words2").html(sightWords[num1]);
$("#words1").html(words1[num1]);
$("#words3").html(words2[num1]);
}
$("h1").click(function(){
if(sightWords.indexOf($(this).text()) > -1){
$(this).css("color","green");
}
else{
$(this).css("color","red");
}
});
h1 {
display: inline-block;
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="question">
<p id = "question"></p>
<h1 id = "words1"></h1><h1 id = "words2"></h1><h1 id = "words3"></h1>
</div>
|
Change the css style of one element in javascript when you click on another element
Date : March 29 2020, 07:55 AM
To fix this issue document.getElementsByClassName() returns an array-like object. To update an element you've to specify an index. var el = document.getElementsByClassName('input-group-addon')[0];
|