Solved

Getting value of <li> using JQuery/JS

Posted on 2016-07-20
3
45 Views
Last Modified: 2016-07-20
I am trying to get the whatever option is clicked values inside the <li> starting from "Advanced" all way to "Status" and "Properties" to "ProdSimple" and "Linked Servers" all way to "SDBUsers" and "Paging Analysis" all way to "RepCmp"

  <nav role="navigation" class="navbar navbar-custom">
      <div class="container-fluid">
          <div class="navbar-header">
            <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <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="#"><img src="images/database_brand.png" alt="Database" /></a>
        </div>
          <div id="navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li id="prm_lnk" class="active"><a href="#">Dashboard</a></li>
                                
                <li class="dropdown" > <a href="#" data-toggle="dropdown">Reports <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                      <li class="dropdown-submenu"><a href="#" tabindex="-1" data-toggle="dropdown">Instance</a>
                        <ul  class="dropdown-menu">
                          <li><a href="#" tabindex="-1">Advanced</a></li>
                          <li'><a href="#" tabindex="-1" id ="agent">Agent</a></li>
                          <li><a href="#" tabindex="-1">General</a></li>
                          <li><a href="#" tabindex="-1">ServerConfig</a></li>
                          <li><a href="#" tabindex="-1">Restart</a></li>
                          <li><a href="#" tabindex="-1">Local Date and Time</a></li>
                          <li><a href="#" tabindex="-1">Alerts & Operators</a></li>
                          <li><a href="#" tabindex="-1">Mail Status</a></li>
                          <li><a href="#" tabindex="-1">Status</a></li>

                        </ul>
                      </li>
                      <li class="dropdown-submenu"><a href="#" tabindex="-1" data-toggle="dropdown">Database</a>
                        <ul class="dropdown-menu">
                          <li><a href="#" tabindex="-1">Properties</a></li>
                          <li><a href="#" tabindex="-1">Backup Properties</a></li>
                          <li><a href="#" tabindex="-1">File Properties</a></li>
                          <li><a href="#" tabindex="-1">Partitioning</a></li>
                          <li><a href="#" tabindex="-1">BackupSizes</a></li>
                          <li><a href="#" tabindex="-1">ProdSimple</a></li>
                        </ul>
                      </li>
                       <li class="dropdown-submenu"><a href="#" tabindex="-1" data-toggle="dropdown">Security</a>
                        <ul class="dropdown-menu">
                          <li><a href="#" tabindex="-1">Linked Servers</a></li>
                          <li><a href="#" tabindex="-1">Local Administrators</a></li>
                          <li><a href="#" tabindex="-1">Logins Not Used</a></li>
                          <li><a href="#" tabindex="-1">Orphaned Users</a></li>
                          <li><a href="#" tabindex="-1">SysAdmins</a></li>
                          <li><a href="#" tabindex="-1">ServerRole Members</a></li>
                          <li><a href="#" tabindex="-1">Blank Passwords</a></li>
                          <li><a href="#" tabindex="-1">AgentProxy</a></li>
                          <li><a href="#" tabindex="-1">SLogins</a></li>
                          <li><a href="#" tabindex="-1">SDBUsers</a></li>
                        </ul>
                      </li>
                         <li class="dropdown-submenu"><a href="#" tabindex="-1" data-toggle="dropdown">Logs</a>
                        <ul class="dropdown-menu">
                          <li><a href="#" tabindex="-1">Paging Analysis</a></li>
                          <li><a href="#" tabindex="-1">Paging Details</a></li>
                          <li><a href="#" tabindex="-1">RepCmp</a></li>
                        </ul>
                      </li>
<%--                      <li><a href="#" tabindex="-1">Oracle Reports</a></li>                     --%>
                    </ul>
                  </li>
            </ul> 

Open in new window

0
Comment
Question by:Member_2_7966896
3 Comments
 
LVL 15

Assisted Solution

by:Ess Kay
Ess Kay earned 250 total points
Comment Utility
$("#dropdown-menu li").click(function() {
    alert(this.id); // id of clicked li by directly accessing DOMElement property
    alert($(this).attr('id')); // jQuery's .attr() method, same but more verbose
    alert($(this).html()); // gets innerHTML of clicked li
    alert($(this).text()); // gets text contents of clicked li
});

Open in new window



hope that helps
1
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 250 total points
Comment Utility
I'm not sure what you are after.  I am going to guess below

http://jsbin.com/bivuhaloni/edit?html,js,output
$(function(){
  
  $('.dropdown-submenu ul.dropdown-menu li').on('click', function(){
    
    alert($(this).text());
    
  });
});

Open in new window

1
 

Author Closing Comment

by:Member_2_7966896
Comment Utility
Thank you guys! Exactly what I was looking for.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now