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');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744798740a4594363.html
评论列表(0条)