How to apply toggle for child elements - javascript

When I clicked the button, the whole side bar is toggling, but I need only the side menus to get toggle.
HTML part
<nav id="sidebar">
<div class="sidebar-header">
<img src="/fintantra/images/logo.jpg" style="margin-left:4px;">
<div class="btn-group">
.....
......
<ul class="list-unstyled components" id="demo">
<li>
<a href="#adminSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-user"></i>
FDR
</a>
<ul class="collapse list-unstyled" id="adminSubmenu">
<li>
<i class="fa fa-arrows-alt" aria-hidden="true"></i> FPO Profile
</li>
....
</ul>
</li>
<li>
<a href="#fisSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-user"></i>
FIS
</a>
<ul class="collapse list-unstyled" id="fisSubmenu">
<li>
<i class="fa fa-arrows-alt" aria-hidden="true"></i> FPO Profile
</li>
....
</ul>
</li>
...
</ul>
</nav>
<button type="button" id="sidebarCollapse" class="btn btn-info">
<i class="fas fa-align-left"></i>
<span>KANCHI</span>
</button>
JS Part
<script type="text/javascript">
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#sidebar').toggleClass('active');
});
});
</script>
The above code is working for the whole sidebar and when I replace ('#sidebar') with ('#demo') it is not toggling. I'm using demo as id in the menu ul section.

<script type="text/javascript">
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#demo').toggleClass('active');
});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#demo').toggle();
});
});
</script>

Related

Add class to iframe inner body when parent body hasclass

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MARA-Web Accounting Solution</title>
<link href="font-awesome-4.3.0/css/font-awesome.css" rel="stylesheet" type="text/css" />
<link href="font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/lib/bootstrap/bootstrap.css" />
<link rel="stylesheet" href="css/styles.css" />
<script src="js/jquery-1.11.1.js" type="text/javascript"></script>
<script src="js/scripts.min.js" type="text/javascript"></script>
<script src="js/lib/bootstrap/bootstrap.min.js" type="text/javascript"></script>
<script src="js/lib/slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="js/lib/tabdrop/bootstrap-tabdrop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/lib/sparklines/jquery.sparkline.min.js"></script>
<script src="js/jquery.blockUI.js" type="text/javascript"></script>
<!-- <script language="javascript" type="text/javascript">
$(window).load(function () {
$("#divLoading").fadeOut("slow");
});
</script>-->
<style type="text/css">
#import url('https://fonts.googleapis.com/css?family=Montserrat');
body
{
font-family: 'Montserrat' , sans-serif !important;
}
</style>
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.get("sessval.ashx", function (data) {
$("#partyval").text(data);
})
})
</script>
<script type="text/javascript">
$(document).ready(function () {
$("iframe>body").css("background-color", "white");
$("a").not('a#logout').click(function (e) {
e.preventDefault();
var hrf = $.trim($(this).attr("href"));
$(this).parent('li').siblings('li').removeClass('select');
$(this).parent('li').addClass('select');
if (hrf) {
try {
$("iframe.external").attr("src", hrf);
}
catch (ex) {
$get('ifrm').src = hrf;
}
}
});
$('ul.menu li:first').addClass('select');
});
$(document).ready(function () {
$('.clickloader').click(function () {
$.blockUI({ css: {
border: 'none',
padding: '15px',
// backgroundColor: '#000',
// '-webkit-border-radius': '10px',
// '-moz-border-radius': '10px',
opacity: .4,
color: '#fff'
}
});
setTimeout($.unblockUI, 1000);
});
});
function getValu() {
var url = window.location.href;
var qparts = url.split("?");
if (qparts.length == 0) {
return "";
}
var query = qparts[1];
var qry = query.split("&")[0];
var parts = qry.split("=");
if (parts[0] == "usn") {
value = parts[1];
return value;
}
}
</script>
<script src="js/lib/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var aaa = $('body').hasClass("left-side-collapsed");
if (aaa == true) {
$("iframe").contents().find('body').addClass('foo');
}
$('.accordion-toggle').on('click', function (event) {
event.preventDefault();
// create accordion variables
var accordion = $(this);
var accordionContent = accordion.next('.accordion-content');
var accordionToggleIcon = $(this).children('.toggle-icon');
// toggle accordion link open class
accordion.toggleClass("open");
// toggle accordion content
accordionContent.slideToggle(250);
// change plus/minus icon
if (accordion.hasClass("open")) {
accordionToggleIcon.html("<i class='fa fa-minus-circle pull-right'></i>");
} else {
accordionToggleIcon.html("<i class='fa fa-plus-circle pull-right'></i>");
}
});
});
</script>
</head>
<body class="left-side-collapsed">
<div>
<header>
<nav class="navbar navbar-default navbar-transparent">
<div class="container" id="nav-container">
<div class="navbar-header">
<button class="navbar-toggle navbar-toggle-settings" data-target="#top-navbar" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<i class="ion ion-ios7-gear-outline"></i></button>
<a class="navbar-brand logo" href="javascript:;">
<img src="images/logo2.png" alt="logo" />
<Label id="complbl" runat="server" CssClass="compn" Height="22px"></Label>
<label ID="fnylbl" runat="server" class="finy" Height="22px"></Label>
</a>
<div class="navbar-side-menu-toggle">
<button class="toggle-btn" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span></button>
</div>
</div>
<div class="collapse navbar-collapse" id="top-navbar">
<nav id="primary_nav_wrap">
<ul>
<li class="menu-item"><a id="logout" href="startingPage.aspx" target="_self"><i class="fa fa-home"></i> Home
</a></li>
<li class="divde">|</li>
<!--<li class="menu-item"></i> Payment</li>
<li class="menu-item"></i> Receipt</li>-->
<li class="menu-item"></i> Transaction</li>
<li class="divde">|</li>
<!--<li class="menu-list "></i> <span> Contra</span> <i class="fa fa-angle-down pull-right"></i>
<ul class="sub-menu-list">
<li >
</i> Cash To Bank</li>
<li >
</i> Bank To Cash</li>
<li >
</i> Bank To Bank</li>
</ul>
</li>-->
<!--<li class="menu-list "></i> <span>A/C Transaction</span> <i class="fa fa-angle-down pull-right"></i>
<ul class="sub-menu-list">
<li>
<i class="fa fa-shopping-cart"></i> Purchase</li>
<li ></i> Sale
</li>
<li ><i class="fa fa-credit-card"></i> Debit Note
</li>
<li></i> Credit Note
</li>
<li></i> Import Purchase
</li>
</ul>
</li>-->
<li class="menu-list "></i> <span> General Setting</span> <i class="fa fa-angle-down pull-right"></i>
<ul class="sub-menu-list">
<li >
</i> Group Ledger</li>
<li>
</i> General Ledger</li>
<li >
</i> Create Ledger</li>
<li >
</i> Modify Ledger</li>
<li>
</i> Customer</li>
<li>
</i> Supplier</li>
<li>
</i> Sales Person</li>
<li>
</i> SAC Code</li>
<li>
</i> HSN Code</li>
<li>
</i> Firm Signatory</li>
<!--<li>
</i> Currency</li>
<li>
</i> Currency Conversion</li>-->
<li>
</i> Lock Entries</li>
<li>
</i> Closing Stock</li>
<!--<li>
</i> Server Utility</li>-->
</ul>
</li>
<li class="divde">|</li>
<li class="menu-list "></i> <span>Base Setting</span> <i class="fa fa-angle-down pull-right"></i>
<ul class="sub-menu-list">
<!--<li >
</i> Service Tax / Charge</li>
<li >
</i> ROE</li>
<li >
</i> New Agent / Vendor</li>
<li >
</i> TDS Base Details</li>
<li >
</i> Section Master</li>-->
<li >
</i> Invoice Setting</li>
<li >
</i> Voucher Setting</li>
<li >
</i> Cost Center</li>
<li>
</i> User List</li>
<li>
</i> Company Profile</li>
<li>
</i> Server Utility</li>
</ul>
</li>
</ul>
</nav>
<ul class="nav navbar-nav navbar-right">
<!--<li>
<a class="top_link1" href="../help_html/index.html" target="parent">Help</a> </li>-->
<li> <a class="top_link1" href="logoutform.aspx">Log Out</a></li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container" id="content-container">
<div class="content-wrapper">
<div class="row">
<div class="side-nav-content">
<div class="left-side-wrapper">
<div class="left-side sticky-left-side">
<div class="left-side-inner">
<ul class="nav nav-pills nav-stacked custom-nav">
<li class="menu-list "><a href="stock/rowmat.aspx"><i class="fa fa-line-chart"></i><span>
Stock (Inventory)</span> <i class="fa fa-angle-down pull-right"></i></a>
<ul class="sub-menu-list">
<li><i class="fa fa-rupee"></i>Price Type</li>
<li><i class="fa fa-tags"></i>Department & Brand</li>
<li><i class="fa fa-tags"></i>Item Master</li>
<li><i class="fa fa-shopping-cart"></i>Item Purchase</li>
<li><i class="fa fa-shopping-cart"></i>Item Sale
</li>
<li><i class="fa fa-shopping-cart"></i>Debit Note
</li>
<li><a href="finance/batchsret.aspx"><i class="fa fa-shopping-cart"></i>Credit Note
</a></li>
<!--<li></i> Sale(Others)
</li>-->
<!--<li></i> Debit Note(Others)
</li>
-->
<li><i class="fa fa-bar-chart"></i>Stock Ledger
</li>
<!--<li></i> Weighted Average </li>
<li></i> FIFO Method</li>-->
<li><i class="fa fa-line-chart"></i>Stock Report</li>
<li><i class="fa fa-area-chart"></i>Sale Report</li>
<li><i class="fa fa-balance-scale"></i>Measurement Unit</li>
</ul>
</li>
<li class="menu-list"><a href="track_reports/updateTranAcHead.aspx"><i class="fa fa-user-o"
aria-hidden="true"></i><span>A/C Reports</span> <i class="fa fa-angle-down pull-right">
</i></a>
<ul class="sub-menu-list">
<li><a href="track_reports/updateTranAcHead.aspx"><i class="fa fa-file-text-o"></i>Alter
Entries</a></li>
<li><a href="track_reports/updateTranAcHead.aspx?id=Trial Balance"><i class="fa fa-file-text-o">
</i>Trial Balance</a></li>
<li><a href="track_reports/updateTranAcHead.aspx?id=Vr Balance Sheet"><i class="fa fa-file-text-o">
</i>Balance Sheet</a></li>
<li><a href="track_reports/updateTranAcHead.aspx?id=Vr PL Sheet"><i class="fa fa-money">
</i>Profit and Loss</a></li>
<li><i class="fa fa-book"></i>Subd. Book</li>
<li><i class="fa fa-file-text-o"></i>Ledger View</li>
<li><i class="fa fa-print"></i>Ledger Print</li>
<li><a href="track_reports/CustStatement.aspx"><i class="fa fa-file-text-o"></i>Customer
Statement</a></li>
</ul>
</li>
<li class="menu-list "><a href="track_reports/ServiceTaxD.aspx"><i class="fa fa-file-text-o">
</i><span>Other Reports</span> <i class="fa fa-angle-down pull-right"></i></a>
<ul class="sub-menu-list">
<li><i class="fa fa-file-text-o"></i>B/L Sheet</li>
<li><i class="fa fa-file-text-o"></i>P/L Statement</li>
<!--<li >
</i> Service Tax Report</li>
<li >
</i> Daily Sale Report</li>-->
<!--<li>
<i class="fa fa-file-text-o"></i> TDS Report</li>-->
<li><i class="fa fa-file-text-o"></i>Debtor Aging</li>
<li><i class="fa fa-money"></i>Cash Flow</li>
<!--<li>
</i> Dvat</li>
<li>
</i> Dvat Sale</li>
</ul>
</li>-->
<li><a href="track_reports/bankrecon.aspx"><i class="fa fa-bank"></i>
Bank Reconciliation</a></li>
<li><a href="finance/brconsole.aspx"><i class="fa fa-file-o"></i><span>
HO/Br Reconcile</span> </a></li>
<li><a href="track_reports/ConsoleR.aspx"><i class="fa fa-file-o">
</i>Consolidation</a> </li>
<li><a href="track_reports/shorting.aspx"><i class="fa fa-file-text-o">
</i>Query Reporting</a> </li>
<li><a href="finance/LedgerMerge.aspx"><i class="fa fa-file-o"></i>
Merge Ledger</a> </li>
<li><a href="GST/SupplierCnsltedrept.aspx"><i class="fa fa-file-powerpoint-o">
</i>Purchase Report</a> </li>
<li><a href="GST/SupplierCnsltedreptSale.aspx"><i class="fa fa-wpforms">
</i>Sales Report</a> </li>
</ul>
</li>
<!--GST MENU -->
<li class="menu-list "><a href=""><i class="fa fa-wpforms"></i><span>GST Forms</span>
<i class="fa fa-angle-down pull-right"></i></a>
<ul class="sub-menu-list">
<li><i class="fa fa-file-text-o"></i>GSTR-1</li>
<li><i class="fa fa-file-text-o"></i>GSTR-2</li>
<li><i class="fa fa-file-text-o"></i>GSTR-3</li>
<!--GST MENU END -->
</ul>
</li>
<li class="menu-list "><a href=""><i class="fa fa-folder-o"></i><span>General Invoice</span>
<i class="fa fa-angle-down pull-right"></i></a>
<ul class="sub-menu-list">
<li><i class="fa fa-file-text-o"></i>General Purchase</li>
<li><i class="fa fa-file-text-o"></i>General Sale</li>
<!--GST MENU END -->
</ul>
</li>
<li class="menu-list "><a href=""><i class="fa fa-upload"></i><span>Bulk Upload</span>
<i class="fa fa-angle-down pull-right"></i></a>
<ul class="sub-menu-list">
<li><i class="fa fa-paypal"></i>General Ledger</li>
<li><i class="fa fa-paypal"></i>Transaction</li>
<!--<li >
</i> rent</li>-->
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="main-content-wrapper">
<iframe name="contentframe" src="mainpage.aspx" class="external left-side-collapsed" scrolling="yes"
width="99.8%" height="600px" style="background-color: #FFFFFF; border: none;"
id="Iframe1"></iframe>
</div>
</div>
</div>
</div>
</div>
<!--<div id='divLoading' style="position:absolute;top:30%;left:40%" >
<div class="loading" align="center" id="divImageLoader">
<img src="images/ajax-loader2.gif" alt="Loading..."/> Loading
</div></div>-->
<footer>
<div class="container">
<div class="row">
<div class="col-md-6 pull-left">
<ul class="list-inline">
<li>
<strong>
<span id="partyval"></span></strong>
</li>
<li><asp:Label ID="dblbl" runat="server" Font-Bold="True" ForeColor="White" Text="Label"></asp:Label></li>
</ul>
</div>
<div class="col-md-6 pull-right">
<ul class="list-inline" style="text-align:right">
<li><Bold> Powered by Maco Infotech. Ltd. </Bold></li>
<li><asp:Label ID="dblbl" runat="server" Font-Bold="True" ForeColor="White" Text="Label"></asp:Label></li>
</ul>
</div>
</div>
</div>
</footer>
</div>
</body>
</html>
I want to add class on iframe inner body a class when my parent body hasClass left-side-collapsed I and try this code but it is not work for me any solution please comment. i have paste the code here you can check the code it is .net file .aspx any solution please comment. ------------------------------------
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
As long as the iframe is loaded this should work...
$("iframe").contents().find('body').addClass('foo');
...maybe go the other way around?
in mainpage.aspx:
$(document).ready(function () {
var p = parent;
if(p.$('body').hasClass('left-side-collapsed')){
$('body').addClass('foo');
}
});
Can you try:
var iframe = document.getElementById("myiframe");
var iframe_doc = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
You should now be able to find the body on iframe_doc. Jquery might be easier to write - $(iframe_doc).find('body') - and then you can add the class.
See these answers for additional reference:
How can I access iframe elements with Javascript?
How do I add a class to a given element?

onclick jquery add/remove class function not working

I'm using single navigation file for all web pages, so i need to add or remove class based on click function. but somehow it's not working fine. any help would be appreciated.
$(function() {
$("li").on("click", function() {
$("li.active").removeClass("active");
$(this).addClass("active");
});
});
<div class="nav-side-menu">
<div class="brand">Brand Logo</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li style="cursor: pointer;" onclick="window.location='new-patient.php';">
<a><i class="fa fa-plus-square"></i>New Patient</a>
</li>
<li style="cursor: pointer;" onclick="window.location='returning-patient.php';">
<a><i class="fa fa-plus-square"></i>Returning Patient</a>
</li>
</ul>
</div>
</div>
$('#menu li a').on('click', function(){
$('#menu li a.current').removeClass('current');
$(this).addClass('current');
});
JSFiddle
You can use following script on every page to set this.
var pageName = (function () {
var a = window.location.href,
b = a.lastIndexOf("/");
return a.substr(b + 1);
} ());
$("#menu-content a").each(function () {
if ($(this).attr('href') == pageName) {
$(this).parents("li").addClass('active');
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="nav-side-menu">
<div class="brand">Brand Logo</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li>
<a href="new-patient.php">
<i class="fa fa-plus-square"></i>New Patient
</a>
</li>
<li>
<a href="returning-patient.php">
<i class="fa fa-plus-square"></i>Returning Patient
</a>
</li>
</ul>
</div>
</div>

How to load HTML page in DIV of the same page when clicking the menu list?

I am trying to convert an html5 example I saw from the web but I am having trouble making the href to load on the same page in the container section, instead of loading into a new page.
I added a jquery script to override the default behaviour of the href and load it to the div but still doesn't seem to work. Below is my HTML and JS codes.
INDEX.HTML
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>MY PROJECT</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="wrapper">
<div class="overlay"></div>
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
<ul class="nav sidebar-nav">
<li class="sidebar-brand">
<a href="#">
MY PROJECT
</a>
</li>
<li>
<i class="fa fa-fw fa-home"></i> Back to Home
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 1
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 2
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 3
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 4
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 5
</li>
<li>
<i class="fa fa-fw fa-cog"></i> HTML 6
</li>
<li class="dropdown">
<i class="fa fa-fw fa-plus"></i> ADVANCE <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Advance</li>
<li>chart mod a</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-dropbox"></i> SLIDE SHOW MODE
</li>
</ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<button type="button" class="hamburger is-closed animated fadeInLeft" data-toggle="offcanvas">
<span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</button>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h1 class="page-header">Reports Control</h1>
<p class="lead">(BETA) </p>
<p>Use nav side bar to select report ...</p>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
INDEX.JS
$(document).ready(function () {
var trigger = $('.hamburger'),
overlay = $('.overlay'),
isClosed = false;
trigger.click(function () {
hamburger_cross();
});
function hamburger_cross() {
if (isClosed == true) {
overlay.hide();
trigger.removeClass('is-open');
trigger.addClass('is-closed');
isClosed = false;
} else {
overlay.show();
trigger.removeClass('is-closed');
trigger.addClass('is-open');
isClosed = true;
}
}
$('[data-toggle="offcanvas"]').click(function () {
$('#wrapper').toggleClass('toggled');
});
$('#wrapper').on('click', function (e) {
e.preventDefault();
var page = $(this).attr('href');
$('#page-content-wrapper').load(page);
});
});
$('#wrapper') is a DIV not the anchor, means that there is no href attributes exist. Instead try used :
// $('#wrapper .nav a') - will look for <a> tag inside of wrapper div at the .nav element
$('#wrapper .nav a').on('click', function (e) {
e.preventDefault();
var page = $(this).attr('href');
$('#page-content-wrapper').load(page);
});
The problem is that your event listener is bound to the #wrapper element which has no href attribute. Inside the event handler function, $(this) refers to the element the handler was bound to, so you need to listen to clicks on the individual <a> elements.
$('.nav a').on('click', function (e) {
e.preventDefault();
var page = $(this).attr('href');
$('#page-content-wrapper').load(page);
});

bootstrap navbar fixed top and body padding top

I am trying to create fixed top navigation when scroll the window and from the point when top area becomes invisible. I did it but I have problem with body padding top when top area becomes visible again. Padding is added automatically to body, but should not, need only to be applied when navbar has an fixed-top class. See the picture (when top area becomes visible)
How to fix that problem with padding?
Site is live here
JavaScript
//FIXED NAVBAR ON SCROLL
$(document).scroll(function(event) {
var wintop = $(window).scrollTop(); // Winodw Scroll Positon
var topArea = $('.top-area').outerHeight(); // Header Logo Div Height
if (wintop > topArea) {
$('.navbar-default').addClass('navbar-fixed-top'); // Fixed Menu
$('body').css('padding-top', parseInt($('.navbar-fixed-top').css("height")) + 1);
} else {
$('.navbar-default').removeClass('navbar-fixed-top'); // Unfixed Menu
}
});
I have bootstrap navigation (navbar navbar-default) which is below top-area on site, this is code
<div class="top-area">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4">
<p class="address">Maršala Tita br. 54, Gložan 21412, Srbija</p>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 information text-right">
<ul class="contact">
<li class="email">support#uram.co.rs
</li>
<li class="telephone">+381 21 788 584</li>
<li class="fax">+381 21 788 584</li>
</ul>
<ul class="social">
<li>
<a href="http://www.facebook.com" target="_blank" title="Pratite nas na Facebook-u">
<i class="fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
<li>
<a href="http://www.plus.google.com" target="_blank" title="Pratite nas na Google plus">
<i class="fa fa-google-plus" aria-hidden="true"></i>
</a>
</li>
<li>
<a href="http://www.twitter.com" target="_blank" title="Pratite nas na Twitter-u">
<i class="fa fa-twitter" aria-hidden="true"></i>
</a>
</li>
<li>
<a href="http://www.vimeo.com" target="_blank" title="Pratite nas na Vimeo">
<i class="fa fa-vimeo" aria-hidden="true"></i>
</a>
</li>
<li>
<a href="http://www.youtube.com" target="_blank" title="Pratite nas na YouTube">
<i class="fa fa-youtube-play" aria-hidden="true"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://mile.x3.rs/mile/uram/" title="Uram System - Dobrodošli">
<img src="http://mile.x3.rs/mile/uram/img/logo.jpg" alt="Uram System Logo">
</a>
</div>
<div class="navbar-collapse collapse" id="navbar-collapse">
<nav>
<ul class="nav navbar-nav">
<?php $currentPage=( basename($_SERVER[ "SCRIPT_NAME"])); ?>
<li <?php if ($currentPage=='index.php' ) { echo "class='active'"; } else {echo '';} ?>>Početna
</li>
<li class="dropdown">
O nama <i class="fa fa-angle-down"></i>
<ul class="dropdown-menu" role="menu">
<li>Naša kompanija
</li>
<li>Istorijat
</li>
<li>Nagrade i priznanja
</li>
<li>Rukovodstvo
</li>
</ul>
</li>
<li>Proizvodi
</li>
<li class="dropdown">
Reference <i class="fa fa-angle-down"></i>
<ul class="dropdown-menu" role="menu">
<li>Fabrika Knjaz Miloš, Aranđelovac
</li>
</ul>
</li>
<li class="dropdown">
Partneri <i class="fa fa-angle-down"></i>
<ul class="dropdown-menu" role="menu">
<li>Partner 1
</li>
<li>Partner 2
</li>
<li>Partner 3
</li>
<li>Partner 4
</li>
<li>Partner 5
</li>
<li>Partner 6
</li>
</ul>
</li>
<li <?php if ($currentPage=='novosti.php' ) { echo "class='active'"; } else {echo '';} ?>>Novosti
</li>
<li class="dropdown">
Download <i class="fa fa-angle-down"></i>
<ul class="dropdown-menu" role="menu">
<li>Download 1
</li>
<li>Download 2
</li>
<li>Download 3
</li>
<li>Download 4
</li>
<li>Download 5
</li>
<li>Download 6
</li>
</ul>
</li>
<li <?php if ($currentPage=='kontakt.php' ) { echo "class='active'"; } else {echo '';} ?>>Kontakt
</li>
<li>
<a style="visibility: visible;" class="search-button" href="#">
<i class="fa fa-search" aria-hidden="true"></i>
</a>
</li>
</ul>
<!-- /.nav navbar-nav -->
<div style="display: none;" class="bg-white hide-show-content no-display header-search-content">
<form class="navbar-form vertically-absolute-middle">
<div class="form-group">
<input placeholder="Unesite pojam za pretragu ovde" class="form-control" id="s" name="s" value="" type="text">
</div>
</form>
<button class="close">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</nav>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</div>
<!-- /.navbar navbar-default navbar-fixed-top -->
Just remove the padding-top in the else statement :
$(document).scroll(function(event) {
var wintop = $(window).scrollTop(); // Winodw Scroll Positon
var topArea = $('.top-area').outerHeight(); // Header Logo Div Height
if (wintop > topArea) {
$('.navbar-default').addClass('navbar-fixed-top'); // Fixed Menu
$('body').css('padding-top', parseInt($('.navbar-fixed-top').css("height")) + 1);
} else {
$('.navbar-default').removeClass('navbar-fixed-top'); // Unfixed Menu
$('body').css('padding-top', '0px');
}
});
Please try this:
$(document).scroll(function(event) {
var wintop = $(window).scrollTop(); // Winodw Scroll Positon
var topArea = $('.top-area').outerHeight(); // Header Logo Div Height
if(wintop > topArea){
$('.navbar-default').addClass('navbar-fixed-top'); // Fixed Menu
$('body').css('padding-top', parseInt($('.navbar-fixed-top').css("height"))-109);
} else {
$('.navbar-default').removeClass('navbar-fixed-top'); // Unfixed Menu
}
});

mmenu doesnt fire onclick event

I am using the mmenu jquery plugin (http://mmenu.frebsite.nl/).
When clicking on items on the menu it doesnt trigger my onclick event. Any ideas why this could be happening would be much appreciated.
<nav id="menu">
<ul>
<li>
<span id="showScanDataBtn">
<i class="menu-icon fa fa-leaf"></i> Scan Data
</span>
</li>
<li>
<span id="showPickingBtn">
<i class="menu-icon fa fa-list"></i> View Picking
</span>
</li>
<li>
<span id="logoutBtn">
<i class="menu-icon fa fa-power-off"></i> Logout
</span>
</li>
</ul>
</nav>
This is the javascript:
$(function () {
$("#showPickingBtn").click(function (e) {
alert("Button Clicked!");
});
});
I have also tried the exact same but with a tags instead just in case the span was causing the issue, but im having the same effect.
How about this?
$("#showPickingBtn").on("click", function (e) {
alert("Button Clicked!");
});
try with ...on('click', function...
$(function () {
$("#showPickingBtn").on('click', function (e) {
alert("Button Clicked!");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="menu">
<ul>
<li>
<span id="showScanDataBtn">
<i class="menu-icon fa fa-leaf"></i> Scan Data
</span>
</li>
<li>
<span id="showPickingBtn">
<i class="menu-icon fa fa-list"></i> View Picking
</span>
</li>
<li>
<span id="logoutBtn">
<i class="menu-icon fa fa-power-off"></i> Logout
</span>
</li>
</ul>
</nav>
Maybe you can use this as example so you just have to set the onclick event once and then inside check for id and do whatever you want with it...
$(function () {
$("#menu").find('li span').on('click', function (e) {
if( $(this).attr('id') === 'showPickingBtn' ) {
alert('CRAZY - ' + 'showPickingBtn' + ' has been clicked');
} else {
alert($(this).attr('id') + ' has been clicked');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="menu">
<ul>
<li>
<span id="showScanDataBtn">
<i class="menu-icon fa fa-leaf"></i> Scan Data
</span>
</li>
<li>
<span id="showPickingBtn">
<i class="menu-icon fa fa-list"></i> View Picking
</span>
</li>
<li>
<span id="logoutBtn">
<i class="menu-icon fa fa-power-off"></i> Logout
</span>
</li>
</ul>
</nav>
this code working for me
$(document).ready(function() {
$("#showPickingBtn").click(function (e) {
alert("Button Clicked!");
});
});

Categories