admin管理员组文章数量:1406760
I am running a loop on a number of elements and trying to access another set of elements using the ids I get in the loop I attempt to refer to other elements and get their tag, here's my code.
function checkRequired(){
var i = 0;
$(".required_div").each(function(index){
if( $(this).html() != '')
{
var question_id = $(this).attr('id').substring(9);
var question_element = $('[name="ry['+question_id+']"');
console.log(question_element);
console.log(question_element.tagName);
}
});
console.log(i);
}
And this is what I get in the console for each element:
1. [textarea#mce_editor_4.tinymce, prevObject: jQuery.fn.jQuery.init[1], context: document, selector: "[name="ry[67]""]
2. undefined
I've also tried to access the tagName using prop as mentioned here but that didn't work as it returns question_element.prop is not a function(…)
.
I am running a loop on a number of elements and trying to access another set of elements using the ids I get in the loop I attempt to refer to other elements and get their tag, here's my code.
function checkRequired(){
var i = 0;
$(".required_div").each(function(index){
if( $(this).html() != '')
{
var question_id = $(this).attr('id').substring(9);
var question_element = $('[name="ry['+question_id+']"');
console.log(question_element);
console.log(question_element.tagName);
}
});
console.log(i);
}
And this is what I get in the console for each element:
1. [textarea#mce_editor_4.tinymce, prevObject: jQuery.fn.jQuery.init[1], context: document, selector: "[name="ry[67]""]
2. undefined
I've also tried to access the tagName using prop as mentioned here but that didn't work as it returns question_element.prop is not a function(…)
.
-
1
try
question_element[0]
– YarGnawh Commented Jan 4, 2016 at 2:31 - @YarGnawh that worked, so $('name=...) gets multiple elements? – Naguib Ihab Commented Jan 4, 2016 at 2:33
1 Answer
Reset to default 6It's returning undefined
because question_element
is a jQuery object.
You could either access a DOM element in the jQuery object, then get the property:
question_element[0].tagName
or you could use the .prop()
method:
question_element.prop('tagName');
本文标签: javascripttagName returns undefinedStack Overflow
版权声明:本文标题:javascript - tagName returns undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744798740a2625734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论