javascript - Grabbing ID Field from Element jQuery Each -


i'm trying cycle through of children in <ul> list, assign onclick event listener , use id of element event. using jquery , jquerymobile in application. reason, id property of element shows blank? when alert actual element, [objecthtmllielement]. when use devtools, id field present in of elements?

this listview

this how trying accomplish this...

function set_onclicks() {     var count = $('#main-listview').children().length;     if (count > 0)     {         $('#main-listview').children().each(function() {             this.onclick = function() {                 project_id = this.id;                 $.mobile.changepage('#main-project-page', 'slide', true, true);             }         });     } } 

can point me in right direction , explain why cannot grab id? in advance help!

nathan

recent edits

i have tried implementing this, know not need bind through .each() loop.

$('#main-listview').children().click(function() {     alert(this);     alert(this.id);     project_id = this.id;     $.mobile.changepage('#main-project-page', 'slide', true, true); }); 

the first alert gives me [ object httmllielement ] next alert gives me blank...?

edit 2 - html example think know why now. jquerymobile adding <div> elements before adds <a> link. now, going have figure out how around this..

<ul data-role="listview" data-inset="true" data-filter="true" data-filter-theme="a" id="main-listview" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">     <li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="a" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-first-child ui-btn-up-a">         <div class="ui-btn-inner ui-li">             <div class="ui-btn-text">                 <a id="51e0278f2a1cb33a08000002" class="ui-link-inherit">123456 - project</a>             </div>             <span class="ui-icon ui-icon-arrow-r ui-icon-shadow">&nbsp;</span>         </div>     </li> </ul> 

i have no idea why using function set click event.. (and no need use loop $.each set click event each elements).

just should work

  $('#main-listview').children().click(function() {              project_id = this.id;             $.mobile.changepage('#main-project-page', 'slide', true, true);         }     }); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -