how do i get div childs from jquery/javascript in this example? -


i'm trying access div's child using jquery's .eq() function, looks something's wrong, despite fact not throwing error, looks when .innerhtml desired child div element, nothing happens.

this html:

<div id="status_container">     <div class="status_item_wrapper">         <div class="status_item_title">             <span>title 1</span>         </div>         <div class="status_item_content">             <table id="box-table"></table>         </div>     </div>     <div class="status_item_wrapper">         <div class="status_item_title">             <span>title 2</span>         </div>         <div class="status_item_content">             <table id="box-table"></table>         </div>     </div> </div> 

and javascript:

function dosomething(message) {      var data = message.data;      var index_container = 0;       var container = $("#status_container").eq(0);      var content_wrapper = container.eq(1); // content div of each child      content_wrapper.html(json.stringify(data)); } 

i thought "title 1" status_item_wrapper div, , then, content_wrapper contain "status_item_content" object.

how supposed reach "status_item_content" div first parent "status_container"?

thanks.

content_wrapper jquery object, eq() returns, , does'nt have innerhtml method, should use jquery's html() :

content_wrapper.html( json.stringify(data) ); 

to return native dom element instead, can use get(), , :

var content_wrapper = container.get(1); content_wrapper.innerhtml = json.stringify(data); 

edit:

now you've added container, there issues. eq() element in collection of elements based on 0 based index, , you're using id selector, there should'nt collection, id's unique, , should select 1 single element.

if you're trying select second child inside #status_container element, you'd do

 var content_wrapper = $("#status_container").children().eq(1); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -