Get Dynamic Div Data Properly With Jquery
I'm a newbie coder. I need to parse some JSON that is extracted from a page with jQuery. I can obtain the desired information from the div, but I'm unable to process it as I need a
Solution 1:
Thanks for your helps devs!
I've find out a solution by reworking my code. I've removed some unnecessary code and I've chained all the methods to parse the parent div who hold the child one that contains the informations I need. The usual syntax like l[0].a[0].preloadImageURIs[0]
will not work and produce a strange error. I've searched on SO for a possible solution to iterate the nested array in the object and I found this interesting solution.I've adapted it for my code:
(function($){
$(document).ready(function(){
console.log('Extension Started!');
var el = $(document).find('#stories_tray');
child = el.find('._827c');
$.each(child, function(i){
var div = $(child[i])
.find('._7h4p')
.attr('data-onkeypress');
var d = JSON.parse(div);
constl = uri => d[0].a.find(e => e.uri).preloadImageURIs;
console.log(l());
});
});
}(jQuery));
Just for curiosity, anyone know how I can split in three separate link the returned values of the array?Now I got what I want but it print all the first one link of the three divs in once.
Post a Comment for "Get Dynamic Div Data Properly With Jquery"