Page 1 of 1

Select all items of a list component

Posted: Sun Jan 10, 2016 8:03 pm
by Matt Simoncavage

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!


Select all items of a list component

Posted: Mon Jan 11, 2016 3:14 pm
by Serhii Kulibaba

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?


Select all items of a list component

Posted: Mon Jan 11, 2016 4:53 pm
by Matt Simoncavage

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!


Select all items of a list component

Posted: Mon Jan 11, 2016 7:17 pm
by Serhii Kulibaba

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


Select all items of a list component

Posted: Mon Jan 11, 2016 9:39 pm
by Matt Simoncavage

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.


Select all items of a list component

Posted: Tue Jan 12, 2016 6:36 pm
by Serhii Kulibaba

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

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


Select all items of a list component

Posted: Tue Jan 12, 2016 10:58 pm
by Matt Simoncavage

Thanks a lot Sergiy, this worked!