I got a multi-select drop-down ordered as a like this:
<ul>
<li title="Africa" aria-selected="false">Africa</li>
<li title="Egypt" aria-selected="false">Egypt</li>
<li title="Angola" aria-selected="false">Angola</li>
<li title="Benin" aria-selected="false">Benin</li>
<li title="Asia" aria-selected="false">Asia</li>
<li title="Taiwan" aria-selected="false">Taiwan</li>
<li title="India" aria-selected="false">India</li>
<li title="Thailand" aria-selected="false">Thailand</li>
<li title="Europe" aria-selected="false">Europe</li>
<li title="Denmark" aria-selected="false">Denmark</li>
<li title="Italy" aria-selected="false">Italy</li>
<li title="Spain" aria-selected="false">Spain</li>
</ul>
What I am aiming for is to disable the continents (Africa, Asia, Europe) so that they are not selectable.
I have figured that if I completely remove the aria-selected="false" attribute + value and add aria-disabled="true" for the continents the become un-selectable.
I thought this was the way to do it for a single continent:
(Preferably there should be a more dynamic way so I don't have to repeat this for each continent)
jQuery( document ).ready(function($) {
$("ul li[title='Africa']").removeAttr("aria-selected");
$("ul li[title='Africa']").attr("aria-disabled","true");
});
..but nothing happens. What am I doing wrong?
try this instead,
I created a array for hidden items
var titles= ["Africa", "Asia", "Europe"];
jQuery( document ).ready(function($) {
var titles= ["Africa", "Asia", "Europe"];
for(var i=0;i<=titles.length;i++){
$("ul li[title="+titles[i]+"]").removeAttr("aria-selected");
$("ul li[title="+titles[i]+"]").attr("aria-disabled","true");
}
});
li[aria-disabled="true"]{
color:#888;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li title="Africa" aria-selected="false">Africa</li>
<li title="Egypt" aria-selected="false">Egypt</li>
<li title="Angola" aria-selected="false">Angola</li>
<li title="Benin" aria-selected="false">Benin</li>
<li title="Asia" aria-selected="false">Asia</li>
<li title="Taiwan" aria-selected="false">Taiwan</li>
<li title="India" aria-selected="false">India</li>
<li title="Thailand" aria-selected="false">Thailand</li>
<li title="Europe" aria-selected="false">Europe</li>
<li title="Denmark" aria-selected="false">Denmark</li>
<li title="Italy" aria-selected="false">Italy</li>
<li title="Spain" aria-selected="false">Spain</li>
</ul>
Related
So I have multiple LI's like below as it's a menu and I am trying to create a drop-down but for some reason, my jQuery code is not working. Can someone help me?
FYI I can't change HTML as it's dynamically generating in Shopify. I can only change jQuery and CSS
<li class="grid__item lvl-1 ">
<a class="site-nav lvl-1 light-body">Furry Artist</a>
<ul class="subLinks inactive">
<li class="lvl-2">
Erdbeer Joghurt
</li>
<li class="lvl-2">
Jeson RC
</li>
</ul>
</li>
$( document ).ready(function() {
$("ul.subLinks").addClass("inactive");
});
$('a.site-nav.lvl-1').click(function() {
$(this).find("ul.subLinks").toggleClass('active-drop-down');
});
.inactive {
display:none;
}
.active-drop-down {
display:block !important;
}
Your issue is $(this).find... in the a click handler - at this point, this is the a.
.find() looks at the selectors children - but the menu is not a child of the a, it's a sibling.
Change to
$(this).closest("li").find("ul.subLinks"...
(maybe $(this).next().toggleClass... with a caveat on .this() that it's always the very next element).
Updated snippet:
$('a.site-nav.lvl-1').click(function() {
$(this).closest("li").find("ul.subLinks").toggleClass('active-drop-down');
});
.inactive {
display:none;
}
.active-drop-down {
display:block !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ol>
<li class="grid__item lvl-1 ">
<a class="site-nav lvl-1 light-body">Furry Artist</a>
<ul class="subLinks inactive">
<li class="lvl-2">
Erdbeer Joghurt
</li>
<li class="lvl-2">
Jeson RC
</li>
</ul>
</li>
</ol>
I have an accordion menu in my website top page.
when click primary menus, accordion toggles using jQuery.
But when link to it from primary menus in another page, it doesn't work.
primary-menu
<ul id="menu-aaa" class="primary-menu">
<li id="menu-item-1">
home</li>
<li id="menu-item-2">
aaa</li>
<li id="menu-item-3">
bbb</li>
</ul>
accordion menu
<div id="aaa" class="testmenu">
<label for="testmenu_bar01"></label>
<input type="checkbox" id="testmenu_bar01" class="accordion">
<ul id="links01">
<li class="testmenu01-li-01">link1</li>
<li class="testmenu01-li-02">link2</li>
<li class="testmenu01-li-03">link3</li>
<li class="testmenu01-li-04">link4</li>
</ul>
</div>
<div id="bbb" class="testmenu">
<label for="testmenu_bar02"></label>
<input type="checkbox" id="testmenu_bar02" class="accordion">
<ul id="links02">
<li class="testmenu02-li-01">link1</li>
<li class="testmenu02-li-02">link1</li>
<li class="testmenu02-li-03">link1</li>
<li class="testmenu02-li-04">link1</li>
</ul>
</div>
jQuery
$(function($){
$("ul.primary-menu > li.menu-item-2 > a").click(function() {
$('input#testmenu_bar01').prop('checked',true);
})
$("ul.primary-menu > li.menu-item-3 > a").click(function() {
$('input#testmenu_bar02').prop('checked',true);
$('li.testmenu01-li-02').css('margin-top','2vh');
})
});
I read this
How open my toggle-accordion from another page?
and I tried to add
$(location.hash).find(.accordion).prop('checked', true);
to my cord, but it was wrong.
Then, I tried this (in my wordpress site)
jQuery(function($){
var url = $(window.location.href);
var hash = url.substring(url.indexOf('#'));
$(hash).find('input[type=checkbox]').prop('checked', true);
});
But it was something wrong, it doesn't work.
I solved the problem by use this jQuery code;
$(location.hash).find('input[type=checkbox]').prop('checked', true);
Thank you.
It is possible to create a two column appearance in a list based on a data attribute of an element?
My HTML which can't really be modified into two lists (even using JS breaks other functionality on the page) looks like:
<ul>
<li data-list="general_results">general text1</li>
<li data-list="general_results">general text2</li>
<li data-list="general_results">general text3</li>
<li data-list="category_results">category text1</li>
<li data-list="category_results">category text2</li>
<li data-list="category_results">category text3</li>
<li data-list="category_results">category text4</li>
</ul>
I want the output to appear as:
general text1 category text1
general text2 category text2
general text3 category text3
category text4
It is same to assume that the will always have the elements grouped in order.
I'm not sure how to achieve this with the desired output. Floating places elements in a left to right fashion instead of a vertical layout.
Any ideas?
If you insert a blank line you can achieve this quite easily using column-count.
div#twoColumn {
-moz-column-count: 2;
-moz-column-gap: 10px;
-webkit-column-count: 2;
-webkit-column-gap: 10px;
column-count: 2;
column-gap: 10px;
line-height:1.5em;
list-style-type:none;
}
<div id="twoColumn">
<ul>
<li data-list="general_results">general text1</li>
<li data-list="general_results">general text2</li>
<li data-list="general_results">general text3</li>
<li data-list="general_results"> </li>
<li data-list="category_results">category text1</li>
<li data-list="category_results">category text2</li>
<li data-list="category_results">category text3</li>
<li data-list="category_results">category text4</li>
</ul>
</div>
Here's what I did...
HTML CODE.. I get the data-list attr value then filter through it and append on different divs.
<ul>
<li data-list="general_results">general text1</li>
<li data-list="general_results">general text2</li>
<li data-list="general_results">general text3</li>
<li data-list="category_results">category text1</li>
<li data-list="category_results">category text2</li>
<li data-list="category_results">category text3</li>
<li data-list="category_results">category text4</li>
</ul>
<div id="gen_text_here">
</div>
<br />
<div id="cat_text_here">
</div>
JQUERY CODE:
$('ul li').each(function(){
if($(this).attr("data-list") == 'general_results'){
$('#gen_text_here').append($(this).attr("data-list") + '<br />');
}else if($(this).attr("data-list") == 'category_results'){
$('#gen_text_here').append($(this).attr("data-list") + '<br />');
}
});
Not a very elegant solution but it does the trick:
[data-list="general_results"] {
float:right;
clear:right;
}
Fiddle here: http://jsfiddle.net/qUAT6/1113/
But I don't support this. The right solution is to separate your elements in two lists.
I have an <ul> to do a menu bar. The bar is vertical on the left of my screen. When an option is selected out of the first visible section, I will use JS to hide the first block and set the remaining blocks to .show()
on the next chunk based on the option selected. Now, I have no problem with the JS portion of this. My problem is - when I .hide() and .show() the <li> groups, they stay as if the others were present (large gaps in between options vs top aligned).
Here is a sample of my list:
<ul class="menu">
<li><a id="mainSuit" href="javascript: void(0)">Suit</a></li>
<li><a id="mainFinances" href="javascript: void(0)">Finances</a></li>
<li><a id="mainMissions" href="javascript: void(0)">Missions</a></li>
<li><a id="mainTerritory" href="javascript: void(0)">Territory</a></li>
<li><a id="mainCompany" href="javascript: void(0)">Company</a></li>
<li><a id="mainTravel" href="javascript: void(0)">Travel</a></li>
</ul>
<!-- More <ul> between the two -->
<ul class="menu">
<li><a id="suitLoadout">Loadout</a></li>
<li><a id="suitEquipment">Equipment Market</a></li>
<li><a id="suitMunitions">Munitions Surplus</a></li>
<li><a id="suitRefuel">Refuel</a></li>
<li><a id="suitRepair">Repair</a></li>
</ul>
For CSS
#suitRepair {
display: none;
}
/* same for all of the IDs */
So when id mainSuit is selected - all of <ul class="menu"> will be hidden and the section for suit is shown.
How would I get it so that any gaps for UL blocks between these too are removed.
Just try specify the id on < li > instead < a >:
<li><a id="suitLoadout">Loadout</a></li>
will be:
<li id="suitLoadout"><a>Loadout</a></li>
Now you will hide the < li > tag not the content of that tag, so the space gap will be solved ;)
UPDATED
Even better - use the <ul> as the identifier and go that route:
<ul id="mainMenu">
<li id="mainSuit"><a onclick="mainSuit()" href="javascript: void(0)">Suit</a></li>
</ul>
<ul id="suitMenu">
<li id="suitLoadout"><a>Loadout</a></li>
<li id="suitEquipment"><a>Equipment Market</a></li>
<li id="suitMunitions"><a>Munitions Surplus</a></li>
<li id="suitRefuel"><a>Refuel</a></li>
<li id="suitRepair"><a>Repair</a></li>
</ul>
With JS of:
function backSelected() {
$("#mainMenu").show();
$("#suitMenu").hide();
}
function mainSuit() {
$("#mainMenu").hide();
$("#suitMenu").show();
}
I'm having a small issue here:
<div id="navbar">
<ul id="navtabs" class="floatcontainer">
<li <?php if ($_GET['dept'] == "home") {echo"class='selected'";} ?>><a class="navtab" href="index3.php?dept=home">Home</a>
<ul class="floatcontainer">
<li>User Panel</li>
<li>Report Bugs</li>
<li>Staff Forums</li>
</ul>
</li>
<li <?php if ($_GET['dept'] == "management") {echo "class='selected'";} ?>><a class="navtab" href="index3.php?dept=management">Management</a>
<ul class="floatcontainer">
<li>User Listing</li>
</ul>
</li>
</ul>
In the code, the correct floatcontainer is meant to show up in each case for the li above, however, the bottom one, the floatcontainer with the User listing li only shows in both cases.
How do I resolve this?
If you don't want the ul showing up unless $_GET['dept'] is some particular value, then put it inside an if() block?