javascript - How to get news_id in alert on item click -


how item id on item click, able display data on in listview want click on item show particular news_id on alert.

this html page :

<body>  <div data-role="page" id="taxmanhomepage"  data-theme="e">   <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="e">    <h4 align="center">taxmann demo app</h4>   </div>   <div data-role="content" data-theme="e">    <a data-role="button" onclick="callservice()">webservice</a>     todays headlines:    <div class="content-primary">     <ul id="newlist" data-role="listview" data-inset="true"data-filter-theme="e" data-divider-theme="e">     </ul>    </div>   </div>  </div> </body> 

this javascript code:

var url="http://www.taxmann.com/taxmannwhatsnewservice/mobileservice.aspx?service=corporatelaws"; var news_id=null; var news_title=null; var news_short_description=null; var new_hash = {}; document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() {}  function backtohome() {     $.mobile.changepage('#taxmanhomepage', {         reverse : false,         changehash : false     }); }  $(document).on('pagebeforeshow','#newslistpage',function(event){   $('#newlist').empty(); });  function callservice(){  $.ajax({   type : "get",   url : url,   datatype : "json",   cache : false,   error : function(xhr, ajaxoptions, thrownerror) {     debugger;   },   success : function(response, status, xhr) {     response=xhr.responsetext;     var responsearray = json.parse(response);     console.log(responsearray);     var length = responsearray.length;     var html='';     for(i=0;i<length;i++) {      news_id=$.trim(responsearray[i].news_id);      news_title=$.trim(responsearray[i].news_title);      news_short_description=$.trim(responsearray[i].news_short_description);      new_hash[news_id]=[news_title,news_short_description];      $("#newlist").append("<li 'style='font-size:10pt';'font-weight:bold';' ><a href='#'  ><h1 class='myheader'>"+news_title+"</h1><br><h6 class='myheader'>"+news_short_description+"</h6></a></li>");   }    $("#newlist").append("</ul>");   $('#newlist').listview('refresh');   $('#newlist').children('li').on('click', function (){    var index = $(this).index();    //var text = $(this).text();    alert(index);   });  }  });   } 

change append part in code this,

$("#newlist").append($("<li/>").data("newsid", news_id).html("<a href='#'  ><h1 class='myheader'>" + news_title + "</h1><br/><h6 class='myheader'>" + news_short_description + "</h6></a>")); 

and change click event this,

$('#newlist').on('click', 'li',function () {     var index = $(this).index();     //var text = $(this).text();     alert($(this).data("newsid")); }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -