jquery - how to use a value (which is get by .text() when a li is clicked) as a selector to hide some div -


i have ul li list like

<ul class="dropdown-menu" id="dropdown">    <li><a id='l1' href='javascript:void(0);'>batch1</a></li>    <li><a id='l2' href='javascript:void(0);'>batch2</a></li>    <li><a id='l3' href='javascript:void(0);'>batch3</a></li>    <li><a id='l4' href='javascript:void(0);'>batch4</a></li>    <li><a id='l5' href='javascript:void(0);'>batch5</a></li>    <li><a id='l6' href='javascript:void(0);'>batch6</a></li> </ul> 

now, can text value of every li, problem is, cannot use text value selector.what want is: have div(id "batch1, batch2...batch6"),which want hide if li clicked(except clicked li). code are=

html:

<div id="batch1"></div>  <div id="batch2"></div> ...... 

jquery:

$(document).ready(function(e) {     $('body').click(function(event) {      if($(event.target).is('#l1')) {        var id = "'#"+$('#l2').text()+"'";        $(id).hide();     } }); }); 

what should do. trying 24 hours still in dark. , in advance

you should add common class #batch1, #batch2 elements can target them @ once..

then use id exception...

html

<div id="batch1" class="batch"></div> <div id="batch2" class="batch"></div> 

javascript

$('#dropdown').on('click','a', function(e){     e.preventdefault();     var id = '#' + $.trim( $(this).text() ); // create id based on text      $('.batch').hide(); // hide batch elements     $(id).show(); // show 1 corresponds clicked li }); 

demo at http://jsfiddle.net/a5vxm/


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -