I am trying to make a small script. I have a main div that has 300 internal divs and I access them through:
$("#items").find(".item").each(function(index,ele){ console.log(ele); })
This way it writes me all the internal divs. Now I want to access the labels and read their internal html of these divs found.
How can i do this? Tried to mess around with ele.labeland ele.$("label"), but it doesn't work.
ele.label
ele.$("label")
You need to use .findor .childrento find child / nested elements.
.find
.children
$(ele).children('label') // takes just direct children $(ele).find('label') // take all nested labels
Try this and let me know if this helps.
$("#items").find(".item").each((i, e) => console.log(e.innerHTML))
html(), innerHTML of label.
html()
label
$("#items").find(".item label").each(function(index,ele){ console.log($(ele).html())});
$("#items").find(".item").each(function(index,ele){ console.log($(ele).find('label').html();)})
javascript:)
itemslabelArr = document.querySelectorAll("#items .item label") for (var i = 0, len = itemslabelArr.length; i < len; i++) { console.log(itemslabelArr[i].innerHTML); }
$("#items .item").each(function(index,element){ var labelText = $('label', element).text(); // or .html() console.log(labelText); })
Source: https://habr.com/ru/post/1691406/More articles:JQuery hides blank space in div - jqueryTf.extract_image_patches implementation - tensorflowHow to select rows with corresponding fields in MySQL? - mysqlWhere is the external code (unsupported / Eigen / CXX11 / Tensor) for the TensorFlow github: - tensorflowlogout does not work, caching on nginx, how to allow logout? - djangoPHP with openSSL public parameter cannot be forced into private key - phpHow to send multiple letters in laravel5.5 - phpDraft.js cannot embed loaded image from external form - javascriptCannot get column names after returning first table from stored procedure in pymssql - pythonRemoving a comma from a number pipe in angular2 - angularAll Articles