Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Select all items of a list component

Hi, I have a list component that pulls content from the database and I'm currently using the following code to perform an action of ONLY the one list item that is selected by the user:

codevar li = jQuery(this).closest("li");/code

My question is, is there a way I can modify the code to perform the action on EVERY list items in the list, instead of only the one selected?

Thanks!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Select all items of a list component

Hello Matt,

Please clarify, do you generate these list items with service's mapping?
What action do you want to run for each list item?

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Select all items of a list component

Hi Sergiy,

Yes the list items are generated from the database through service's mapping. I currently have it working with the code shown above, the specific action being to hide / show an element in the list item using .hide(); and .show() commands. For example, if each list item contains a button, I'm able to hide or show ONLY the one I click on with .closest();. Now what I want to do is take the same idea, but hide or show EVERY list item's button on that click instead. Hope this clarifies and thanks!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Select all items of a list component

Please add JS below on click event of the list item to hide button "myButton" in that list item:
pre$(this).find("[name=myButton]").hide();/pre

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Select all items of a list component

Hi Sergiy, thanks again for the reply. Sorry, I don't think I was clear enough. I already know how to hide the button in that list item. What I want to do is hide the buttons in all other list items except that one.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Select all items of a list component

So, you have to hide all buttons:
$("[name=myButton]").hide();

and after that to show this one button:
$(this).find("[name=myButton]").show();

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Select all items of a list component

Thanks a lot Sergiy, this worked!

Return to “Issues”