+ 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"); }); });
9 Answers
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' ;)
0
Right and when i execute this code it doesn't work as it should,it stays only in one color
0
file:///C:/Users/ACER/Documents/web/prueba.html?
0
saved it in my profile, didnt add the jquery because i dont know how to use it in the sololearn compiler lol
0
oh thought that i added it to my profile in public
- 1
provide the link of your code...
- 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)
- 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)
- 1
no: your profile show still zero codes ^^