-1

Can you check if I return a function correct:

JS
$(eachsection).each(function() {
   listfunction();
}


function listfunction(){
  $(this).show();
  $(this).find('a.q_weblinksprite_med').attr("onclick", construct_url);
  $(this).find('.q_weblinksprite_med').text(itemTitle);
  $(this).find(".status").text(itemStatus);
  $(this).find('.q_rt_rowcell-1-title').text(itemCategory);
  $(this).find('.q_clipline').html(itemContent);
}

What I want is just to return all content from listfunction(). Thanks!

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
prince
  • 449
  • 2
  • 5
  • 6
  • Right now you're not returning anything in any function..what is it exactly that you need? – cviejo Nov 11 '15 at 15:24
  • 1
    from this snippet I see that you haven't closed each method, then try to write this way `$(eachsection).each(listfunction); function listfunction(){ ... return $(this); }` – Danil Gudz Nov 11 '15 at 15:51
  • well just print or debug what your method returns and you'll know if its correct... that's how i see it... – mikus Nov 11 '15 at 16:11
  • Possible duplicate of [Remove .php extension with PHP](http://stackoverflow.com/questions/1337695/remove-php-extension-with-php) – mikus Nov 11 '15 at 16:13

2 Answers2

1

The code you posted isn`t returning anything.

By the look, you could return a array

function listfunction(){
  var myReturn = {};
  $(this).show();
  myReturn['url'] = $(this).find('a.q_weblinksprite_med').attr("onclick", construct_url);
  myReturn['title'] = $(this).find('.q_weblinksprite_med').text(itemTitle);
  myReturn['status'] = $(this).find(".status").text(itemStatus);
  myReturn['category'] = $(this).find('.q_rt_rowcell-1-title').text(itemCategory);
  myReturn['content'] = $(this).find('.q_clipline').html(itemContent);
  return myReturn;
}

Is this what you are looking for?

Alan Rezende
  • 348
  • 2
  • 11
0

Calling listfunction() from where you have it will cause you to lose scope. So if you are attempting to call $(this).show() and have it show the element you looped through, you would need to call it like this:

$(eachsection).each(function() {
   listfunction(this);
}


function listfunction(element){
  $(element).show();
  $(element).find('a.q_weblinksprite_med').attr("onclick", construct_url);
  $(element).find('.q_weblinksprite_med').text(itemTitle);
  $(element).find(".status").text(itemStatus);
  $(element).find('.q_rt_rowcell-1-title').text(itemCategory);
  $(element).find('.q_clipline').html(itemContent);
}
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92
Z. Jensen
  • 16
  • 2