0
<div id="radiodiv1">
         <ul id="span1" data-role="listview">
         <li>value1</li>
         <li>value2</label></li>
         </ul>
  </div>
  <br>
  <table style="border:none;">
  <tr>
  <td>
    <input type="text" id="item" />
 </td>
 <td>
    <input type="button" value="Add params to list" onclick="appendToList()"/>
    </td>
</tr>
        </table>

script

$(document).on("click", "#bizParams", function(e) {
    $("#span1").find("li").each(function(){
       var product = $(this);
       // rest of code.
       console.log(product);
});
});

when clicked the button am getting in log as

Object[li.ui-li-static.ui-body-inherit.ui-first-child]
Object[li.ui-li-static.ui-body-inherit.ui-last-child]

i have to get the values as value1 and value2

can someone say what was wrong here

5 Answers5

0

Use

console.log(product.text());

(it is plain vanilla jQuery)

Barry
  • 3,683
  • 1
  • 18
  • 25
0

You want to get the text() property, not the entire object, change this:

console.log(product);

to this:

console.log(product.text());
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

problem is with this line

var product = $(this);

You have to extract text

var product = $(this).text(); 
Gibbs
  • 21,904
  • 13
  • 74
  • 138
0
$("#myid li").click(function() {
    alert(this.id); // id of clicked li by directly accessing DOMElement property
    alert($(this).attr('id')); // jQuery's .attr() method, same but more verbose
    alert($(this).html()); // gets innerHTML of clicked li
    alert($(this).text()); // gets text contents of clicked li
});

jquery get the id/value of LI after click function

Community
  • 1
  • 1
KiV
  • 2,225
  • 16
  • 18
0

you should use :

        $(document).on("click", "#bizParams", function(e) {
    $("#span1").find("li").each(function(){
       var product = $(this);
       // rest of code.
       console.log(product.text());
});
});

bur before that add the id="bizParams" to your button.

 <input type="button" id="bizParams"value="Add params to list" />
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
  • 1
    besides adding a id `bizParams` to the button ... there is no need of using `.on()`(event delegation) here it should be used when we are adding html dynamically inside DOM ... you can use simple `.click()` here..@keerthanaalivelu – Kartikeya Khosla Nov 11 '14 at 10:41
  • i did not change it because it was not doing any wrong. – Suchit kumar Nov 11 '14 at 10:47