Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to i toggle a class on an Li element that is on a seperate page from my click function
    text
    copied!<p>I am attempting to create a dynamic favorites list in this application i'm working on. My problem at the moment is I cannot direct an event to toggle specific li class names. I have a large list of li's and seperate pages associated with them. Each page has a title bar with several image links, phone number, etc. the last image is a star which i need to have turn blue when the user clicks on it as well as toggle the class of its corresponding li element on another page. I don't want to have to write individual code for each element and i am becoming more frustrated trying to correlate each star click with one of 37 li elements... i have used jquery but cannot figure this out...</p> <p>div containing li elements i need to toggle in order to clone them to another "favorites" list</p> <pre><code>&lt;div id="barlist"&gt; &lt;div class="toolbar"&gt;&lt;h1&gt;Bar List&lt;/h1&gt;&lt;a class="button back"Back&lt;/a&gt; &lt;a class="button flip" Settings&lt;/a&gt; &lt;/div&gt; &lt;ul class="edgetoedge"&gt; &lt;li class="aleHouse"&gt;&lt;a Ale House&lt;/a&gt;&lt;/li&gt; &lt;li class="argyle"&gt;&lt;a Argyle&lt;/a&gt;&lt;/li&gt; &lt;li class="bearlys"&gt;&lt;a Bearlys&lt;/a&gt;&lt;/li&gt; &lt;li class="bostonPizza"&gt;&lt;a&gt;Boston Pizza&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>corresponding page with star image</p> <pre><code>&lt;div id="aleHouse"&gt; &lt;div class="toolbar"&gt;&lt;h1&gt;Ale House&lt;/h1&gt;&lt;a class="button back" &gt;Back&lt;/a&gt; &lt;/div&gt; &lt;div&gt; &lt;div class="blackBar"&gt; &lt;img class="white" img src=".../whitestar40(png)" alt="star"&gt; &lt;/div&gt; $("document").ready(function() { $("#barlist li[class=fav]").clone().appendTo("#favorites[class=edgetoedge]"); }); $("document").ready(function() { $(".white").click(function() { $(???this???).toggleClass(".fav"); }) }); </code></pre> <p>for instance, when the whitestar40 is clicked, i want it to turn blue and also clone the the ale house li (which was clicked to get to this page) and appendTo my favorites list on another page</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload