The jQuery command (‘:hover’) doesn’t work if I insert this code in the beginning of the php document
<script type="text/javascript">
var uid = <?php echo $uid; ?>;
</script>
I am able to use $uid from javascript but then the weird thing is that javascript starts to have problem finding if my mouse is hovering over an element?
Update: I found a solution, putting<script>...</script>at the end of the document solved it, but WHY???
I think that I have disproved what you think has been happening.
Try out this sample code - it seems to work fine.
<?php
$uid = '12345';
?>
<script type="text/javascript">
var uid = <?php echo $uid; ?>;
</script>
<style>
p:hover {
background: green;
}
</style>
<p>Sample text that should get a green background on hover.</p>
<script>
document.body.innerHTML += "<p>UID is " + uid + "</p>";
</script>
Hey Paul, I haven’t been able to come back to this problem since last time I posted, due to a recently deadline I have to meet. But oh boy did you put the problem to the test! I will follow suit and perform similar test tomorrow.
My main purpose in playing around with these codes is actually to use the .is(:hover) function of an object. The hover() seems to work fine with your example, but it doesn’t give you the status of whether something is hovered.
I will do more tests and come back with a good answer.
Oh that’s good to know. I swear that is(‘:hover’) was working for me at some point but maybe the expression was bugged.
The reason why I needed to check hover state is because I have three containers, container A inside container B, and lastly container C containing both A and B.
I want A to disappear whenever the user’s mouse leaves B, but it has to stop the behaviour if the user moves mouse from B to A.
I guess if hover is replaced completely by mouseenter and mouseleave, I can create an event for A.mouseenter that will stop event propagation. It’s a workaround that I think can work. If the devs decided to replace hover they must think that mouseenter mouseleave can cover all the functionalities of hovering.
[quote=“johnhuichen, post:8, topic:198652, full:true”]
I want A to disappear whenever the user’s mouse leaves B, but it has to stop the behaviour if the user moves mouse from B to A.
I guess if hover is replaced completely by mouseenter and mouseleave, I can create an event for A.mouseenter that will stop event propagation. [/quote]
What you have there is a common situation, that is solved by using the mouse leave event on B, and using the .parents method to check that you cannot see B.