admin管理员组

文章数量:1355522

I'm trying to use JQuery to have a method fire when the following code gets clicked:

<div class="content_sub_list">
    <img src="/imgs/close-icon.jpg" class="exit_sub_list"/>
    hello
</div>

It is not doing anything and my JQuery code looks like this:

    $(document).ready(
function() 
{ 
    $('#my_accnt').click(
    function() 
    {
      $('.content_sub_list').css("display", "block");
      $('.content_sub_list').css("margin-left", "4px");
      $('.content_sub_list').html('<div class="sub_list_header">My A<img src="/imgs/close-icon.jpg" class="exit_sub_list"/></div><BR />text');
    });
    $('#my_queue').click(
    function() 
    {
      $('.content_sub_list').css("display", "block");
      $('.content_sub_list').css("margin-left", "165px");
      $('.content_sub_list').html('<div class="sub_list_header">My Q<img src="/imgs/close-icon.jpg" class="exit_sub_list"/></div><BR />text');
    });
    $('.exit_sub_list').click(
    function() 
    {
        alert("hi");
      $('.content_sub_list').css("display", "none");
    });
});

My header looks like this:

    <script src="/js/jquery.js" type="text/javascript"></script>
    <script src="/js/mContentBar.js" type="text/javascript"></script>

Other functions work in it except this one? for some reason. So what am I doing wrong, or how i can get this to work? Thanks

I'm trying to use JQuery to have a method fire when the following code gets clicked:

<div class="content_sub_list">
    <img src="/imgs/close-icon.jpg" class="exit_sub_list"/>
    hello
</div>

It is not doing anything and my JQuery code looks like this:

    $(document).ready(
function() 
{ 
    $('#my_accnt').click(
    function() 
    {
      $('.content_sub_list').css("display", "block");
      $('.content_sub_list').css("margin-left", "4px");
      $('.content_sub_list').html('<div class="sub_list_header">My A<img src="/imgs/close-icon.jpg" class="exit_sub_list"/></div><BR />text');
    });
    $('#my_queue').click(
    function() 
    {
      $('.content_sub_list').css("display", "block");
      $('.content_sub_list').css("margin-left", "165px");
      $('.content_sub_list').html('<div class="sub_list_header">My Q<img src="/imgs/close-icon.jpg" class="exit_sub_list"/></div><BR />text');
    });
    $('.exit_sub_list').click(
    function() 
    {
        alert("hi");
      $('.content_sub_list').css("display", "none");
    });
});

My header looks like this:

    <script src="/js/jquery.js" type="text/javascript"></script>
    <script src="/js/mContentBar.js" type="text/javascript"></script>

Other functions work in it except this one? for some reason. So what am I doing wrong, or how i can get this to work? Thanks

Share Improve this question edited Apr 23, 2011 at 20:19 Eric asked Apr 23, 2011 at 19:38 EricEric 1,2684 gold badges20 silver badges40 bronze badges 4
  • works fine for me... jsfiddle/HX7Kz – Hristo Commented Apr 23, 2011 at 19:41
  • Its working bro test here – Ketan Modi Commented Apr 23, 2011 at 19:42
  • 1 Have you put the code in the document.ready handler? – Felix Kling Commented Apr 23, 2011 at 19:43
  • are you attaching it to the document? because if you are you might be going to the wrong directory or have a typing error. Just had a problem with this last night (spent 2 hours on a bug that ended up I was attaching a js file with a type of text/javasript. – chromedude Commented Apr 23, 2011 at 19:52
Add a ment  | 

1 Answer 1

Reset to default 5

This is working for me. Make sure you have jQuery loaded properly. You can either place jquery.js after your html or wrap your jquery code with a document.ready function.

like

(function() {
    $('.exit_sub_list').click(

    function() {
        alert("hi");
    });
});

Check working example at http://jsfiddle/p6Q2d/

本文标签: javascriptJQuery click text in spanStack Overflow