Hi all, I'm very new to code and doing some practice on jQuery.
I'm trying to use jQuery (aware that @media query would be
probably easier as CSS only solution) to have background images fade
in and out on on selected words of a text with a .hover() event.
As all the images have the same CSS properties, they share the same
class, and (obviously) jQuery doesn't make the distinction of
which specific one to fade in/out, if not instructed to do so. Which
is what I am struggling with.
Here the basic HTML structure. <p> has the CSS property
display: inline; and I'm using <span> to select the desired words.
<div>
<p>Text text text text <span>SHOW IMAGE
<div class="bg">
<img src="image.jpg"/>
</div></span>
</p>
<p>other text other text <span>SHOW OTHER IMAGE
<div class="bg">
<img src="other-image.jpg"/>
</div></span>
</p>
</div>
The script is as follows. It works, but the result is that it shows
always the last image on the HTML. I've tried out option with
'this', or $(this).siblings('.bg'), and even .find(),
but none of them worked.
It's surely very simple, but can't figure it out ;)
Hi everyone, I'm really super new to coding and after some classes
at codecademy I'm now doing some exercises on my own to eventually
build up my own website.
At the moment I'm trying to have js remove a class from a div
and add a second class according to the window width (obviously, unsuccessfully)
Here's my attempt
$(window).resize(function(){
var st = $('.standard');
var al = $('.align-left');
if ($(window).width() < 600) {
st.removeClass('standard');
st.addClass('align-left');
}
});
$(document).ready(main);
On the html file I've included the following just before the
closing </body> tag and my js file is saved as app.js in the
main folder.