admin管理员组文章数量:1241083
I am migrating from PrototypeJS to jQuery, and I'm having issues with applying functionality to new DOM elements added into a simple banner script.
Basically, on page load, new DIV elements are being placed into the DOM using append(), as I understand, this is how it's done in jQuery as opposed to Prototype's Element object.
$.each(Banner.data, function(i, e) {
$('#banner_area').append("<div class='banner_slot' id='bannner-"+ i +"'>...[nested elements]</div>").hide();
});
$('.banner_slot').get(0).show();
Upon checking Firebug, the elements have successfully been added to the DOM, and are immediately hidden. Then the first (0) element should show... however, Firebug give me this error:
TypeError: $(...).get(...).show is not a function
.js
Line 15
I'm sure this is something simple, as I've been using Prototype for years, but need to move to jQuery because, well... more people use it so the resources are infinitely better.
Is there some fundamental difference between the two that I'm missing here?
I am migrating from PrototypeJS to jQuery, and I'm having issues with applying functionality to new DOM elements added into a simple banner script.
Basically, on page load, new DIV elements are being placed into the DOM using append(), as I understand, this is how it's done in jQuery as opposed to Prototype's Element object.
$.each(Banner.data, function(i, e) {
$('#banner_area').append("<div class='banner_slot' id='bannner-"+ i +"'>...[nested elements]</div>").hide();
});
$('.banner_slot').get(0).show();
Upon checking Firebug, the elements have successfully been added to the DOM, and are immediately hidden. Then the first (0) element should show... however, Firebug give me this error:
TypeError: $(...).get(...).show is not a function
http://www.ten103./javascript/global_desktop.js
Line 15
I'm sure this is something simple, as I've been using Prototype for years, but need to move to jQuery because, well... more people use it so the resources are infinitely better.
Is there some fundamental difference between the two that I'm missing here?
Share Improve this question asked Jul 11, 2015 at 15:53 mwieczorekmwieczorek 2,2527 gold badges34 silver badges39 bronze badges 2-
instead of
$('.banner_slot').get(0).show()
, try using$('.banner_slot')[0].show()
– Miguel Ike Commented Jul 11, 2015 at 15:55 -
6
Use the proper method, just replace
get
witheq
– adeneo Commented Jul 11, 2015 at 15:56
2 Answers
Reset to default 10$('.banner_slot').get(0).show();
change to
$('.banner_slot').eq(0).show();
.get()
returns DOM element while .eq()
returns jQuery object and .show()
is jQuery API.
For more information about .get()
and .eq()
checkout the jQuery API docs
You need to update
$('.banner_slot').get(0).show();
to
$($('.banner_slot').get(0)).show();
Note : get()
gives you a DOM Element and show()
is applicable on jQuery object, hence, you need to convert it into jQuery object to use the function.
本文标签: javascriptjQuery show() not a functionused in adding DOM elementsStack Overflow
版权声明:本文标题:javascript - jQuery show() not a function - used in adding DOM elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740104218a2224991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论