Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My List having
- <li class="add"><a href="#">Data1</a></li>
- <li class="add"><a href="#">Data2</a> </li>
- ...
- $(".add").click(function(e){
- e.preventDefault();
- // Here is to get the Value of Data1 and data2 ..
- // How to alert Data1,Data2 effectively
- });
- $('li.add a').each(function() {
- data.push($(this).text());
- });
- $('.add').click(function(e) {
- e.preventDefault();
- // Initialize an array for all texts
- var data = [];
- // For each <li> with class 'add'...
- $('li.add').each(function() {
- // ...append the element's text to the data array
- data.push($(this).text());
- });
- // Just for testing: Alert the array as a string
- alert(data.join(','));
- });
- $('.add').click( function(e){
- e.preventDefault();
- data = [];
- //loop over each li:
- $('li.add').each( function() {
- //Get the a and the text contents of that
- data.push($(this).find('a').text());
- }
- alert(data.join(','));
- }
Add Comment
Please, Sign In to add comment