使用jQuery在li中找到clicked标签的id [英] find id of clicked tag within li using jQuery

查看:48
本文介绍了使用jQuery在li中找到clicked标签的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用jquery获取标签的id然后根据点击的那个显示隐藏的div,但它不想从列表中触发click方法。我的代码如下。提前致谢



im trying to get the id of the tag using jquery then show the hidden div based on which one was clicked, but it doesnt want to fire the click method from within the list. my code is below. thanks in advance

$(function(){

            $('#myList li a').click(function () {
	            var i = $(this).attr('id');
	            alert(i);

	            var k = '#' + i + 'Content';
	            $(k).removeClass('hidden');
	        });

       });










<div id="myList-nav" class="listNav"></div>
                                <ul id="myList">
                                    <li><a href="#" id="section_A.1">Accommodation</a></li>
                                    <li><a href="#" id="section_A.2">Accreditation</a></li>
                                    <li><a href="#" id="section_A.3">Airport</a></li>
                                </ul>
                            </div>










<div id="section_A.1_content" class="hidden">
                               <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tempor pellentesque nibh. Mauris eget lorem molestie, consequat odio quis, porta mauris. Fusce imperdiet quam eget nunc accumsan gravida.  </p>
                           </div>

推荐答案

(function(){
(function(){


' #myList li a')。click(function(){
var i =
('#myList li a').click(function () { var i =


this )。attr(' id');
alert(i);

var k = ' #' + i + ' 内容';
(this).attr('id'); alert(i); var k = '#' + i + 'Content';


这篇关于使用jQuery在li中找到clicked标签的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆