简体   繁体   中英

jQuery $.fn not working with no errors

I've seen this question asked before and googled but to no avail. I'm trying to learn how to create my own function in jQuery but it doesn't do what I'm asking and I'm not receiving any errors. Have I done something wrong here?

Here's the script

<script type='text/javscript'> 
    (function($){ 
        $.fn.selectMe = function(options){ 
            return this.each(function(){ 
               $(this).find('li').append("<input type='checkbox'>"); 
            }); 
        } 
    }(jQuery)); 
    $(document).ready(function(){ 
        $('.Select').selectMe(); 
    }); 
</script>

For good measure, here's the HTML

<div class='Select'>
    <p>Cuisine Types (3/10)</p>
    <ul>
        <li>American</li>
        <li>Italian</li>
        <li>Chinese</li>
    </ul>
</div>

Thanks!

Not sure with the problem though. but I observed:

  • <script type = 'text/javscript'> should be <script type='text/javascript'>
  • (function ($) { }(jQuery)); should be: (function($){ })(jQuery);

This works great. Try this:

 (function($){ $.fn.selectMe = function (options) { return this.each(function () { $(this).find('li').append("<input type = 'checkbox'>"); }); } })(jQuery); $(document).ready(function () { $('.Select').selectMe(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class = 'Select'> <p>Cuisine Types (3/10)</p> <ul> <li>American</li> <li>Italian</li> <li>Chinese</li> </ul> </div> 

Ok! Facepalm! I can't believe I wasted 2 hours on this and everyones time. I spelled javascript wrong and it threw off all the code but no errors. I'm sorry all but thank you for all the feedback!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM