Get selected checkboxes from a dropdown - javascript

I have checkboxes inside a dropdown menu. I've to get the checkboxes which are selected (checked)
Code:
<ul role="menu" class="dropdown-menu" id="comp">
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Monday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Tuesday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Wednesday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Thursday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Friday</span>
</a>
</li>
</ul>
<input type="submit" class="btn btn-info" onclick="myFunction()" value="Submit">
<script type="text/javascript">
function myFunction()
{
/* Get selected check boxes here */
}
</script>

You can try this solution also. Here you will get the checked checkbox elements list. You can also update this checked element list during run time also.
Check the following demo:
Fiddle Demo
Stack Example
$(function() {
var checkedItems = $("#comp input:checked");
console.log(checkedItems);
$("#comp input[type='checkbox']").change(function() {
if ($(this).attr("checked") == "checked") {
checkedItems.push($(this)[0]);//Add the checked element
console.log(checkedItems);
} else {
checkedItems.splice($.inArray($(this)[0], checkedItems), 1);//Remove the unchecked element
console.log(checkedItems);
}
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<ul role="menu" class="dropdown-menu" id="comp">
<li>
<a href="#">
<input type="checkbox" id="a1">
<span class="lbl"> Monday</span>
</a>
</li>
<li>
<a href="#">
<input type="checkbox" id="a2">
<span class="lbl"> Tuesday</span>
</a>
</li>
<li>
<a href="#">
<input type="checkbox" id="a3" checked="checked">
<span class="lbl"> Wednesday</span>
</a>
</li>
<li>
<a href="#">
<input type="checkbox" id="a4">
<span class="lbl"> Thursday</span>
</a>
</li>
<li>
<a href="#">
<input type="checkbox" id="a5">
<span class="lbl"> Friday</span>
</a>
</li>
</ul>

Check the console for selected checkboxes.
function myFunction(){
var checkBoxes=$("#comp input[type=checkbox]:checked");
console.log(checkBoxes);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul role="menu" class="dropdown-menu" id="comp">
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Monday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Tuesday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Wednesday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Thursday</span>
</a>
</li>
<li><a href="#">
<input type="checkbox">
<span class="lbl"> Friday</span>
</a>
</li>
</ul>
<input type="submit" class="btn btn-info" onclick="myFunction()" value="Submit">

Try it, it will return all selected checkbox values as you select any checkbox:
<ul role="menu" class="dropdown-menu" id="comp">
<li><a href="#">
<input name="chklist" onclick="get_selected_val()" value="monday" type="checkbox">
<span class="lbl"> Monday</span>
</a></li>
<li><a href="#">
<input name="chklist" onclick="get_selected_val()" value="tuesday" type="checkbox">
<span class="lbl"> Tuesday</span>
</a></li>
<li><a href="#">
<input name="chklist" value="wednesday" onclick="get_selected_val()" type="checkbox">
<span class="lbl"> Wednesday</span>
</a></li>
<li><a href="#">
<input name="chklist" onclick="get_selected_val()" value="thursday" type="checkbox">
<span class="lbl"> Thursday</span>
</a></li>
<li><a href="#">
<input name="chklist" onclick="get_selected_val()" value="friday" type="checkbox">
<span class="lbl"> Friday</span>
</a></li>
</ul>
function get_selected_val() {
$('input[name="chklist"]:checked').each(function() {
console.log(this.value);
});
}

Related

Unable to jQuery list item when passing with parent div in selector

I have a div which has a ul and list items in it.
<div class="col-md-2"><input id="jackSerachBox" class="form-control input-md m-t-sm" type="text" placeholder="Search for Jacks.."></div>
<div class="col-md-2">
<ul class="nav nav-pills nav-stacked" id="jacksTab">
<li role="presentation" class="active">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-3" name="selectedjacks" value="3">
<label class="text-muted text-uppercase small">NEW40206 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
<li role="presentation" class="">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-6" name="selectedjacks" value="6">
<label class="text-muted text-uppercase small">NewJack12 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
<li role="presentation" class="">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-4" name="selectedjacks" value="4">
<label class="text-muted text-uppercase small">Jack12 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
</ul>
</div>
I am trying to access it using :
$('#jackSerachBox').on('keyup', function (e) {
var input, filter, ul, li, a, i;
// filter = input.val().toUpperCase();
li = $('#jacksTab li');
li.each(function (e) {
a = $('a', $(e)).eq(0);
console.log(a.html())
//test.html(a.html())
})
})
But getting undefined. I did ask similar question , but that was answered with the context. To be fair , had marked that as answer and did not post follow ups on that.
To be more accurate this time here is the jsfiddle for same.
Simply use this inside your .each instead of using a parameter :
If you don't want to use this, you need to edit your .each() parameters to .each(_, e), since the first parameter from the callback is the index of the element.
See the jQuery#each documentation
$('#jackSerachBox').on('keyup', function(e) {
$('#jacksTab li').each(function() {
console.log($('a', this).html())
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-2"><input id="jackSerachBox" class="form-control input-md m-t-sm" type="text" placeholder="Search for Jacks.."></div>
<div class="col-md-2">
<ul class="nav nav-pills nav-stacked" id="jacksTab">
<li role="presentation" class="active">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-3" name="selectedjacks" value="3">
<label class="text-muted text-uppercase small">NEW40206 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
<li role="presentation" class="">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-6" name="selectedjacks" value="6">
<label class="text-muted text-uppercase small">NewJack12 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
<li role="presentation" class="">
<a data-toggle="tab" class="dd-handle">
<input type="checkbox" id="JackcheckBox-4" name="selectedjacks" value="4">
<label class="text-muted text-uppercase small">Jack12 </label> <span><i class="fa fa-hdd-o text-info small"></i></span>
</a>
</li>
</ul>
</div>

How to get selected elements from a ul?

I've created a form and a part of this form is a list which has five elements. These elements can be hovered by mouse. The hovered elements have class of selected. The question is how can I take the value of this elements in order to send it to server?
<ul id="service" class="icon-group booking-item-rating-stars">
<li id="1">
<i class="fa fa-smile-o"></i>
</li>
<li id="2">
<i class="fa fa-smile-o"></i>
</li>
<li id="3">
<i class="fa fa-smile-o"></i>
</li>
<li id="4">
<i class="fa fa-smile-o"></i>
</li>
<li id="5">
<i class="fa fa-smile-o"></i>
</li>
</ul>
If I understand you correct this is what you need:
$('#service li').on('hover', function() {
sendToServer($(this).text());
});
And if you need to check selected class:
$('#service li').on('hover', function() {
var $this = $(this);
if ($this.hasClass('selected')) {
sendToServer($this.text());
}
});
Try this demo, if your <li> looks like this:
<li>
<input type="hidden" id="3" value="3">
<i class="fa fa-smile-o">c</i></li>
<li>
demo:
$(function() {
$('#service li').hover(function() {
$(this).addClass('selected'); // add selected class on hover
var data = $(this).find(':hidden').val(); // get input hidden value inside the li
sendToServer(data); // call send to server function passing data variable
}, function() {
$(this).removeClass('selected');
});
});
function sendToServer(data) {
console.log(data);
// insert send to server program here
}
.selected {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="service" class="icon-group booking-item-rating-stars">
<li>
<input type="hidden" id="1" value="1">
<i class="fa fa-smile-o">a</i></li>
<li>
<input type="hidden" id="2" value="2">
<i class="fa fa-smile-o">b</i></li>
<li>
<input type="hidden" id="3" value="3">
<i class="fa fa-smile-o">c</i></li>
<li>
<input type="hidden" id="4" value="4">
<i class="fa fa-smile-o">d</i></li>
<li>
<input type="hidden" id="5" value="5">
<i class="fa fa-smile-o">e</i></li>
</ul>

How to keep parent li opened when i clicked the child li element

<li>
<a href="#">
<i class="entypo-tools"></i>
<span class="title">PHP-SDK</span>
<span class="badge badge-secondary">3</span>
</a>
<ul>
<li class="dropdown-submenu">
<a href="/mypage_v2/sdk/installation">
<i class="entypo-inbox"></i>
<span class="title">Installation</span>
</a>
</li>
<li class="dropdown-submenu">
<a href="/mypage_v2/sdk/getStarted">
<i class="entypo-docs"></i>
<span class="title">Getting Started</span>
</a>
</li>
<li>
<a href="#">
<i class="entypo-flash"></i>
<span class="title">API-Endpoints</span>
<span class="badge badge-info">3</span>
</a>
<ul>
<li>
<a href="#">
<i class="entypo-newspaper"></i>
<span class="title">sample1</span>
<span class="badge badge-success">4</span>
</a>
<ul>
<li>
<a href="/mypage_v2/sdk/newsletter">
<i class="entypo-newspaper"></i>
<span class="title">sample1</span>
</a>
</li>
<li>
<a href="/mypage_v2/sdk/newsletterEmail">
<i class="entypo-newspaper"></i>
<span class="title">sample2</span>
</a>
</li>
<li>
<a href="/mypage_v2/sdk/newsletteranalytics">
<i class="entypo-newspaper"></i>
<span class="title">sample2</span>
</a>
</li>
<li>
<a href="/mypage_v2/sdk/sample2">
<i class="entypo-newspaper"></i>
<span class="title">NewslettersProcess</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
If you use php rendering and on menu item click page refreshes, you can add class for example "active" to parent li(s), and in styles add li.active {display:block} or something like that style to show hidden elements
Finally i am ok with the condition of laravel routes
<li #if(Request::path() == "mypage_v2/applications/lists" || Request::path() == "mypage_v2/applications/register") class="active opened")#endif>

Jquery accordion collapsed on page load

I am trying to create an expandable accordion using jquery. I am not able to figure out that how am I supposed to prevent it from expanding on page load. I have no idea of jquery,and any help will be greatly appreciated.
<ul>
<li class="expandable root">
<label for=" Oraganization" class="active"> Oraganization</label>
<span class="pull-right oraganization active expand-icon glyphicon glyphicon-minus"></span>
<ul id="accordion">
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-minus"></span>
<input type="checkbox" id="Manager-1">
<label for="Manager-1"> Manager-1</label>
<ul id="accordion">
<li>
<input type="checkbox" id="Sub-Manager-1">
<label for="Sub-Manager-1"> Sub-Manager-1</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-minus"></span>
<input type="checkbox" id="Sub-Manager-2">
<label for="Sub-Manager-2"> Sub-Manager-2</label>
<ul class="accordion">
<li>
<input type="checkbox" id="Associate-1">
<label for="Associate-1"> Associate-1</label>
</li>
<li>
<input type="checkbox" id="Associate-2">
<label for="Associate-2"> Associate-2</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-minus"></span>
<input type="checkbox" id="Associate-5">
<label for="Associate-5"> Associate-5</label>
<ul class="accordion">
<li>
<input type="checkbox" id="Sub-associate-1">
<label for="Sub-associate-1"> Sub-associate-1</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-2">
<label for="Sub-associate-2"> Sub-associate-2</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-3">
<label for="Sub-associate-3"> Sub-associate-3</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-4">
<label for="Sub-associate-4"> Sub-associate-4</label>
</li>
</ul>
</li>
</ul>
</li>
</li>
</ul>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-plus"></span>
<input type="checkbox" id="Manager-2">
<label for="Manager-2"> Manager-2</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-plus"></span>
<input type="checkbox" id="Manager-3">
<label for="Manager-3"> Manager-3</label>
</li>
</ul>
</li>
</ul>
JS File:
$(document).ready(function(){
$('.expand-icon').click(function(){
var elem = $(this);
if(elem.hasClass('active')) {
elem.removeClass('active');
var subElem = elem.siblings('ul');
var nestedElem =elem.siblings('ul').find('ul');
if(nestedElem.length == 0) {
subElem.slideUp('fast');
}
else {
nestedElem.slideUp('fast',function(){
subElem.slideUp('fast');
});
}
$.when(elem.removeClass('glyphicon-minus')).then(function(){
elem.addClass('glyphicon-plus');
});
}
else {
elem.addClass('active');
elem.siblings('ul').slideDown('fast',function(){
elem.siblings('ul').find('ul').slideDown('fast');
});
$.when(elem.removeClass('glyphicon-plus')).then(function(){
elem.addClass('glyphicon-minus');
});
}
});
$('.expandable :checkbox').on('change', function() {
$(this).parent().find('li input[type=checkbox]').prop('checked', $(this).is(':checked'));
var sibs = false;
$(this).closest('ul').children('li').each(function () {
if($('input[type=checkbox]', this).is(':checked')) sibs=true;
});
$(this).parents('ul').siblings(':checkbox').prop('checked', sibs);
});
});
You an find the bootply at this link: http://www.bootply.com/1W8bSTnmx6
Fiddle Here
This is because you have this first accordian open when loading it. To fix it, do a click operation on this at the time of load with $($('#accordion .expand-icon')[0]).click();. Check the working example here http://www.bootply.com/vGoKbvfKtl
you are just displaying all the accordions when the page gets loaded since there is no hiding any where.
According to your code Since only the first Accordion contains the data, it is getting displayed else every expandable div will get displayed.
The solution for this is to add a hide class to the class accordion so that it does not display at the beginning, the at the time of click function, you can remove that class and it gets displayed.
$(document).ready(function(){
$('.expand-icon').click(function(){
$('ul').removeClass('hide')
var elem = $(this);
if(elem.hasClass('active')) {
elem.removeClass('active');
var subElem = elem.siblings('ul');
var nestedElem =elem.siblings('ul').find('ul');
if(nestedElem.length == 0) {
subElem.slideUp('fast');
}
else {
nestedElem.slideUp('fast',function(){
subElem.slideUp('fast');
});
}
$.when(elem.removeClass('glyphicon-minus')).then(function(){
elem.addClass('glyphicon-plus');
});
}
else {
elem.addClass('active');
elem.siblings('ul').slideDown('fast',function(){
elem.siblings('ul').find('ul').slideDown('fast');
});
$.when(elem.removeClass('glyphicon-plus')).then(function(){
elem.addClass('glyphicon-minus');
});
}
});
$('.expandable :checkbox').on('change', function() {
$(this).parent().find('li input[type=checkbox]').prop('checked', $(this).is(':checked'));
var sibs = false;
$(this).closest('ul').children('li').each(function () {
if($('input[type=checkbox]', this).is(':checked')) sibs=true;
});
$(this).parents('ul').siblings(':checkbox').prop('checked', sibs);
});
$('.organization').click(function(){
$('.accordion')[0].click()
})
});
<ul>
<li class="expandable ">
<label for=" Oraganization" class="active"> Oraganization</label>
<span class=" organization active expand-icon glyphicon glyphicon-minus"></span>
<ul id="">
<li class="expandable">
<span class="expand-icon glyphicon glyphicon-plus"></span>
<input type="checkbox" id="Manager-1">
<label for="Manager-1"> Manager-1</label>
<ul class="accordion hide">
<li>
<input type="checkbox" id="Sub-Manager-1">
<label for="Sub-Manager-1"> Sub-Manager-1</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-minus"></span>
<input type="checkbox" id="Sub-Manager-2">
<label for="Sub-Manager-2"> Sub-Manager-2</label>
<ul class="accordion">
<li>
<input type="checkbox" id="Associate-1">
<label for="Associate-1"> Associate-1</label>
</li>
<li>
<input type="checkbox" id="Associate-2">
<label for="Associate-2"> Associate-2</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-minus"></span>
<input type="checkbox" id="Associate-5">
<label for="Associate-5"> Associate-5</label>
<ul class="accordion">
<li>
<input type="checkbox" id="Sub-associate-1">
<label for="Sub-associate-1"> Sub-associate-1</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-2">
<label for="Sub-associate-2"> Sub-associate-2</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-3">
<label for="Sub-associate-3"> Sub-associate-3</label>
</li>
<li>
<input type="checkbox" id="Sub-associate-4">
<label for="Sub-associate-4"> Sub-associate-4</label>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-plus"></span>
<input type="checkbox" id="Manager-2">
<label for="Manager-2"> Manager-2</label>
</li>
<li class="expandable">
<span class="expand-icon active glyphicon glyphicon-plus"></span>
<input type="checkbox" id="Manager-3">
<label for="Manager-3"> Manager-3</label>
</li>
</ul>
</li>
</ul>
Here is the bootply,
Bootply link for it

<a> Links in a sidebar aren't clickable when Javascript is present

I have a sidebar on my new website that toggles sections open and closed, and it does this.
However in any browser, only when the JS script is present, I can no longer actually click the inside links.
Also, there are no errors in the console.
Please can you help me, i'm out of ideas :)
Here is the JS,
(function($) {
"use strict";
$.fn.tree = function() {
return this.each(function() {
var btn = $(this).children("a").first();
var menu = $(this).children("ul").first();
var isActive = $(this).hasClass('active');
//initialize already active menus
if (isActive) {
menu.show();
btn.children(".fa-angle-left").first().removeClass("fa-angle-left").addClass("fa-angle-down");
}
//Slide open or close the menu on link click
btn.click(function(e) {
e.preventDefault();
if (isActive) {
//Slide up to close menu
menu.slideUp();
isActive = false;
btn.children(".fa-angle-down").first().removeClass("fa-angle-down").addClass("fa-angle-left");
btn.parent("li").removeClass("active");
} else {
//Slide down to open menu
menu.slideDown();
isActive = true;
btn.children(".fa-angle-left").first().removeClass("fa-angle-left").addClass("fa-angle-down");
btn.parent("li").addClass("active");
}
});
/* Add margins to submenu elements to give it a tree look */
menu.find("li > a").each(function() {
var pad = parseInt($(this).css("margin-left")) + 10;
$(this).css({"margin-left": pad + "px"});
});
});
};
}(jQuery));
$('<i class="fa fa-angle-left pull-right"></i>').appendTo('.nav-left > li > a');
/* Sidebar tree view */
$(".sidebar .nav-left li").tree();
And this is the HTML:
<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="/img/avatar3.png" class="img-circle" alt="User Image" />
</div>
<div class="pull-left info">
<p>Hello, <span class="insert_usrdata_name"></span></p>
<i class="fa fa-circle text-success"></i> Online
</div>
</div>
<!-- search form -->
<form action="#" method="get" class="sidebar-form">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Search..."/>
<span class="input-group-btn">
<button type='submit' name='seach' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
</span>
</div>
</form>
<!-- /.search form -->
<ul class="nav-left">
<li>
<a title="Go to dashboard" class="icon-0" href="/index">Home</a>
</li>
<li>
<a title="Files" class="icon-1" href="/files">Files</a>
<ul>
<li>
<a title="File Manager" class="visibility-on" href="/files/file-manager">File Manager</a>
</li>
<li>
<a title="File Manager 2" class="visibility-on" href="/files/manager-2" target="_blank">File Manager 2</a>
</li>
<li>
<a title="Backups" class="visibility-on" href="/files/backups">Backups</a>
</li>
<li>
<a title="Error Logs" class="visibility-on" href="/files/error-logs">Error Logs</a>
</li>
<li>
<a title="FTP Details" class="visibility-on" href="/files/ftp-access">FTP Details</a>
</li>
<li>
<a title="FTP Accounts" class="visibility-on" href="/files/ftp-accounts">FTP Accounts</a>
</li>
<li>
<a title="FTP Login History" class="visibility-on" href="/files/ftp-login-history">FTP Login History</a>
</li>
</ul>
</li>
<li class="active">
<a title="Accounts" class="icon-2" href="/accounts">Accounts</a>
<ul>
<li>
<a title="Getting Started" class="visibility-on" href="/accounts/start">Getting Started</a>
</li>
<li class="active">
<a title="Account Details" class="visibility-on" href="/accounts/details">Account Details</a>
</li>
<li>
<a title="Change Password" class="visibility-on" href="/accounts/change-password">Change Password</a>
</li>
<li>
<a title="Change Language" class="visibility-on" href="/accounts/change-language">Change Language</a>
</li>
<li>
<a title="Change Theme" class="visibility-on" href="/accounts/change-theme">Change Theme</a>
</li>
</ul>
</li>
<li>
<a title="Emails" class="icon-3" href="/emails">Emails</a>
<ul>
<li>
<a title="Webmail" class="visibility-on" href="/emails/webmail">Webmail</a>
</li>
<li>
<a title="Email Accounts" class="visibility-on" href="/emails/manage">Email Accounts</a>
</li>
<li>
<a title="Forwarders" class="visibility-on" href="/emails/forwarders">Forwarders</a>
</li>
<li>
<a title="Sent Mail Logs" class="visibility-on" href="/emails/sent-mail-logs">Sent Mail Logs</a>
</li>
<li>
<a title="Mail Service Control" class="visibility-on" href="/emails/mail-service-control">Mail Service Control</a>
</li>
<li>
<a title="Edit MX Record" class="visibility-on" href="/emails/mx">Edit MX Record</a>
</li>
</ul>
</li>
<li>
<a title="Domains" class="icon-4" href="/domains">Domains</a>
<ul>
<li>
<a title="Subdomains" class="visibility-on" href="/domains/subdomains">Subdomains</a>
</li>
<li>
<a title="Parked Domains" class="visibility-on" href="/domains/parked">Parked Domains</a>
</li>
<li>
<a title="New Domain" class="visibility-on" href="/domains/addon">New Domain</a>
</li>
<li>
<a title="Redirects" class="visibility-on" href="/domains/redirects">Redirects</a>
</li>
</ul>
</li>
<li>
<a title="Website" class="icon-5" href="/website">Website</a>
<ul>
<li>
<a title="Statistics" class="visibility-on" href="/website/stats">Statistics</a>
</li>
<li>
<a title="Latest Visitors" class="visibility-on" href="/website/latest-visitor-report">Latest Visitors</a>
</li>
<li>
<a title="Error Pages" class="visibility-on" href="/website/error-pages">Error Pages</a>
</li>
<li>
<a title="Analyze Website" class="visibility-on" href="http://hosting.1pagerank.com/msdhosting.co.uk" target="_blank">Analyze Website</a>
</li>
<li>
<a title="Import Website" class="visibility-on" href="/website/import">Import Website</a>
</li>
<li>
<a title="Import Database" class="visibility-on" href="/website/database-import">Import Database</a>
</li>
<li>
<a title="Website Templates" class="visibility-on" href="/website/website-templates">Website Templates</a>
</li>
<li>
<a title="Script Installer" class="visibility-on" href="/website/auto-installer">Script Installer</a>
</li>
<li>
<a title="Website Builder" class="visibility-on" href="/website/builder" target="_blank">Website Builder</a>
</li>
<li>
<a title="Zyro Builder" class="visibility-on" href="/website/zyro-builder" target="_blank">Zyro Builder</a>
</li>
</ul>
</li>
<li>
<a title="Advanced" class="icon-6" href="/advanced">Advanced</a>
<ul>
<li>
<a title="DNS Zone Editor" class="visibility-on" href="/advanced/dns-zone-editor">DNS Zone Editor</a>
</li>
<li>
<a title="PHP Configuration" class="visibility-on" href="/advanced/phpinfo">PHP Configuration</a>
</li>
<li>
<a title="PHP Version" class="visibility-on" href="/advanced/php-configuration">PHP Version</a>
</li>
<li>
<a title="SSH Console" class="visibility-on" href="/advanced/ssh-console">SSH Console</a>
</li>
<li>
<a title="MySQL Databases" class="visibility-on" href="/advanced/mysql-databases">MySQL Databases</a>
</li>
<li>
<a title="phpMyAdmin" class="visibility-on" href="/advanced/phpmyadmin">phpMyAdmin</a>
</li>
<li>
<a title="Cron Jobs" class="visibility-on" href="/advanced/cronjobs">Cron Jobs</a>
</li>
<li>
<a title="Cron Output" class="visibility-on" href="/advanced/cron-output">Cron Output</a>
</li>
</ul>
</li>
<li>
<a title="Other" class="icon-7" href="/other">Other</a>
<ul>
<li>
<a title="Password Protect Directories" class="visibility-on" href="/other/password-protect-dirs">Password Protect Directories</a>
</li>
<li>
<a title="IP Deny Manager" class="visibility-on" href="/other/ip-deny">IP Deny Manager</a>
</li>
<li>
<a title="Hotlink Protection" class="visibility-on" href="/other/hotlink-protection">Hotlink Protection</a>
</li>
<li>
<a title="Folder Index Manager" class="visibility-on" href="/other/folder-index-manager">Folder Index Manager</a>
</li>
<li>
<a title="Fix File Ownership" class="visibility-on" href="/other/fix-file-ownership">Fix File Ownership</a>
</li>
<li>
<a title="Reset Account" class="visibility-on" href="/other/reload-account">Reset Account</a>
</li>
</ul>
</li>
</ul>
</section>
<!-- /.sidebar -->
</aside>
Thanks for you're time, I would post a link to the real thing, but it seems that is not praised on here...
Within your loop you're setting e.preventDefault() on each link's click event, preventing the click from doing anything:
var btn = $(this).children("a").first();
...
btn.click(function(e) {
e.preventDefault();
...
}
You're calling this on every single a element within your .nav-left list. I don't really know what your desired result is, but if you remove that the links will now function as normal, but the page will change and your click function will have no effect on the new page.
Edit: From comments:
Would you be able to adapt it so that when a parent <a> that doesn't have a <ul> inside is clicked, the link works, and when the parent <a> does have a <ul>, the e.preventDefault(); is enforced on the parent <a>?
Yes, simply add a check around the click function to see whether the a element has a ul element next to it:
if (btn.next('ul').length) {
btn.click(function(e) {
...
}
}

Categories

Resources