jquery hover not applying to child node - php

I need the hover function on "type of worker" and "where do you work?" on the right sidebar (under the contact for) to be a lot cleaner. What i need is for the child ul to remain visible when i hover over the ul and not just the parent link right now if i mouse out of the parent link
Here is my code
<div class="nav_item">
<div class="nav_item_link" id="clickMe2" href="#"><img src="http://50.28.46.210/dev/obryan/wp-content/themes/wp-foundation/images/compassicon.png" class="nav_icons">
<h5>Where Do You Work?</h5></a>
</div>
<ul id="clickEvent2" class="worker_list">
<li>Pacific Ocean</li>
<li>Atlantic Ocean</li>
<li>Gulf of Mexico</li>
<li>Bering Sea</li>
<li>Great Lakes</li>
<li>International Waters</li>
<li>Mississippi River</li>
<li>Ohio River</li>
</ul>
</div>
And here is my jquery
$(document).ready(function(){
$('#clickMe').hover(function() {
$("#clickEvent").fadeToggle("slow");
});

Posting as an answer as requested: http://jsfiddle.net/hgEV9/
$('#clickMe').on("mouseenter",function() {
$("#clickEvent2").fadeToggle("slow");
})
HTML:
<div class="nav_item">
<a class="nav_item_link" id="clickMe" href="#"><img src="http://50.28.46.210/dev/obryan/wp-content/themes/wp-foundation/images/compassicon.png" class="nav_icons"></a>
</div>
<h5>Where Do You Work?</h5>
<ul id="clickEvent2" class="worker_list">
<li>Pacific Ocean</li>
<li>Atlantic Ocean</li>
<li>Gulf of Mexico</li>
<li>Bering Sea</li>
<li>Great Lakes</li>
<li>International Waters</li>
<li>Mississippi River</li>
<li>Ohio River</li>
</ul>
</div>

Related

Struggling to create drop down menu on side bar in html

I have a side menu and I have a lot of menu item so I would like to include drop down menus to group them. while it is almost working I need a way for it to expand and contract when the property menu is clicked on to reveal or hide the sub menu
This is my code
<li class="sub-menu dcjq-parent-li">
<a class="dcjq-parent active" href="javascript:;">
<i class="fa fa-desktop"></i>
<span>Properties</span>
<span class="dcjq-icon"></span></a>
<ul class="sub" style="display: block;">
<li>Manage</li>
<li class="active">Add</li>
</ul>
</li>
This appears correctly but when the user clicks on properties I would like it to either open or close the sub menu.
Could someone help me with this please
<script>
$(document).ready(function () {
$('.dropdown-toggle').dropdown();
});
'''add this script in your code'''

Jquery .hover displaying all arrow glyphicons in li tags that is inside foreach loop

I'm a bit confused on how to properly insert my .hover() function inside my foreach li tags. cause when ever I hover my cursor on the assigned class all of the tags displays the glyphicon content.
here is my code.
jQuery(function() {
jQuery(".side-nav").hover(function() {
jQuery('.hover-arrow-right').show();
});
});
<nav class="side-nav">
<ul>
<?php foreach($posts as $p): ?>
<a href="<?php echo get_permalink($p->ID);?>">
<li>
<?php echo $p->post_title; ?><span class="hover-arrow-right"><i class="fa fa-chevron-right"></i></span>
</li>
</a>
<?php endforeach; ?>
</ul>
</nav>
the proper output is the glyphicon must only show when the cursor is placed on a li respectively.
sorry for my bad english.
thank you. hope anyone can help me in my problem.
you should do hover on the li
jQuery(function() {
jQuery(".side-nav ul a > li").hover(function() {
jQuery(this).find('.hover-arrow-right').show();
});
});

menu link which show a div in another div

I created a menu with links (#) which aims to show & hide a div thanks to the onclick attribute.
For example the link "home" can hide/show the div "contentHome", the link "contact" can hide/show the div "contentContact".
The problem I have is that the container div "content" includes the div "contentHome" and "contentContact" when i click on the 2 links one time...
Here is a part of my code :
<li><a href="#" onclick="toggle('contentHome');" ><?php echo $lang['MENU_ACCUEIL'];?>
<div id="content">
<div id="contentHome">
<img src="Images/photo.jpg" class="imgphoto" alt="Simplepic" />
<?php echo $lang['TEXTE_ACCUEIL'];?>
<img src="Images/work.png" class="imgwork" height="100" width="100" alt="Travaux" />
<?php echo $lang['TEXTE_SOON'];?>
</div>
<div id="contentContact">
...
</div>
</div>
The position is static, I can't put a z-index and when I put display:none;, divs don't want to load.
What do you think ? I just wanted to create a dynamic menu with div but the php includes makes me struggle...
Here i've created some example of toggle with divs.
<li>Toggle Red</li>
<li>Toggle Blue</li>
<div id="content">
<div class="toggled-item" id="contentHome">
<div style="width:200px; background-color:#f00; height:200px;"></div>
</div>
<div class="toggled-item" id="contentContact">
<div style="width:200px; background-color:#00f; height:200px;"> </div>
</div>
</div>
<script>
$(document).ready(function(){
$("#lnk_contentHome, #lnk_contentContact").click(function(){
$(".toggled-item").hide();
var target = $(this).attr("id").split("_")[1];
$("#" + target).toggle();
});
});
</script>
https://jsfiddle.net/ow7dd12f/5/
Hope helps.

How can I make expandable panels without using JS?

My question is how can I create expandable panels in an HTML form without using javascript, so that when a user clicks on each panel it expands and displays the form.
Before click:
<ul>
<li id="panel1"><a></a><div class="content"></div></li>
<li id="panel2"><a></a><div class="content"></div></li>
<li id="panel3"><a></a><div class="content"></div></li>
</ul>
After click:
<ul>
<li id="panel1">
<a></a>
<div class="content">
<form id="FORM"> ..... </form>
</div>
</li>
<li id="panel2"><a></a><div class="content"></div></li>
<li id="panel3"><a></a><div class="content"></div></li>
</ul>
You can do that using :target css pseudo selector - it is not very elegant though, as clicking on the anchor tag modifies the url so it is hard to toggle the form. Best use javascript.
<style>
form {
display: none;
}
form:target {
display: block;
background: red;
}
</style>
<ul>
<li id="panel1" ><div class="content">Show form<form id="form" > My form <input type="text"></form></div></li>
<li id="panel2"><div class="content">My content</div></li>
<li id="panel3"><div class="content">My content</div></li>
</ul>
some examples of :target in action:
http://css-tricks.com/css-target-for-off-screen-designs/ and http://css-tricks.com/on-target/
Without using ANY javascript at all, you can't.
Unless you just put links and redirect your users to a page with the expanded content every time.
Or unless you write some kind of complex CSS using the :hover pseudo-selector and not the click event.
CSS 3 has a :target pseudo-selector that might help. Here is an example: https://tinker.io/1756b

using jQuery to load php files into a div not working

so I have my main layout as such:
<div class="menu">
<?php include('/menu.php'); ?>
</div>
<div class="main" id="content">
<?php include('/home.php'); ?>
</div>
In the menu.php I have 4 divs set up as such:
<div class="link current">
<a href="#" class="home">
Home
</a>
</div>
<div class="link">
<a href="#" class="about">
About
</a>
</div>
<div class="link">
<a href="#" class="forums">
Forums
</a>
</div>
<div class="link">
<a href="#" class="contact">
Contact
</a>
</div>
And I'm including this .js file in the head of the index page
$(function () {
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
if($('div.link a').hasClass('home')) {
$('#content').load('/home.php');
} else if($('div.link a').hasClass('about')) {
$('#content').load('/about.php');
} else if($('div.link a').hasClass('forums')) {
$('#content').load('/forums.php');
} else if($('div.link a').hasClass('contact')) {
$('#content').load('/contact.php');
} else return false;
});
});
But it doesn't work.
I'm new to all of this and have pieced this code together using varied sources on the internet, after trying it myself and not being able to figure it out, I've come for help.
The hierarchy of the site is as such.
-/
-res/
-css/
-default.css
-imgs/
-scripts/
-jquery.js
-load.js (this is the one shown above)
-index.php
-menu.php
-home.php
-about.php
-forums.php
-contact.php
If anyone can provide help, it will be greatly appreciated.
The first condition in your if statements is checking to see if any "div.link a" has the class "home". Therefore the first if condition is always true and you're always loading /home.php into #content. What you want to do is check to see if the link that was clicked has the class.
You should use if($(this).hasClass('home')) { ...
Also, if you want to clean things up a bit, I would suggest:
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
$('#content').load('/' + $(this).attr('class') + '.php');
});
This way you don't have to maintain the if statements. Though, if you end up adding more classes to those links, this will break. Perhaps use a data-* attribute? <a href="#" data-load="contact">...

Categories