+ 1

how does it works?

'use strict' $(function(){ var div=$("#div1"); div.mouseover(function(){ console.log("cliqueado"); var that=div; if(that.css("background")!="green") that.css("background","green"); else that.css("background","black"); }); });

9th Jul 2021, 11:37 PM
Yami Francø
Yami Francø - avatar
9 ответов
0
assign to 'div' variable the jQuery reference of html element with id 'div1' assign to that 'div' a function to use as event listener on 'mouseover', so when mouse overing element (mouse move when over element or one of its children), function is executed: assign to 'that' variable the reference inside 'div' at running time (if 'div' has been reassigned meanwhile it may refer to another element or not be a jQuery reference ^^) check if style attribute contains a 'background' css property has a value different of 'green', if so set it to 'green', else set it to 'black'... so when mouse move over target element (always element with id 'div1') toggle 'background' css property of 'div' (since its a jQuery reference) between 'green' and 'black' ;)
10th Jul 2021, 12:02 AM
visph
visph - avatar
0
Right and when i execute this code it doesn't work as it should,it stays only in one color
10th Jul 2021, 12:09 AM
Yami Francø
Yami Francø - avatar
0
file:///C:/Users/ACER/Documents/web/prueba.html?
10th Jul 2021, 12:12 AM
Yami Francø
Yami Francø - avatar
0
saved it in my profile, didnt add the jquery because i dont know how to use it in the sololearn compiler lol
10th Jul 2021, 12:28 AM
Yami Francø
Yami Francø - avatar
0
oh thought that i added it to my profile in public
10th Jul 2021, 4:38 PM
Yami Francø
Yami Francø - avatar
- 1
provide the link of your code...
10th Jul 2021, 12:10 AM
visph
visph - avatar
- 1
that's the url (file protocol) of your code in the filesystem of your PC: copy the file content in the html tab of a 'web' code playground project, save it and share the link (you can get the link either from the opened code playground project by clicking on the 'share' button option or by clicking the + menu in a post writing field, select 'Insert Code', display 'My Codes' by using the drop down list, and click on the code you want to insert)
10th Jul 2021, 12:18 AM
visph
visph - avatar
- 1
you must set it to 'public' if you want to be listed in your codes for every one ^^ (else you can share the link yourself, but I can't find it in your profile ;P) also, what's the jQuery version you use? I will try to add it myself (if you do not use it from a CDN -- ie: from internet, conversely to have dowloaded it locally)
10th Jul 2021, 12:45 AM
visph
visph - avatar
- 1
no: your profile show still zero codes ^^
10th Jul 2021, 5:50 PM
visph
visph - avatar