Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i manipulate a link or a link's parent if the html in the link equals something?
    primarykey
    data
    text
    <p><strong>EDIT:</strong> may have messed up the question. meant "if the html in the link equals a php variable"</p> <p>so let's say we have an unordered list menu on a page where database values are coming in. i want to add active class to a link that has same value as a database variable. how do i do that? i would like to be able to do it with text values and number values.</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;text1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;text2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;text3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;500&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;1000&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)"&gt;1500&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>so let's say these variables are on the page:</p> <pre><code>$var1 &amp; $var2 </code></pre> <p>echoing those out like this:</p> <pre><code>&lt;p&gt;&lt;?php echo $var1; ?&gt;&lt;/p&gt; &lt;p&gt;&lt;?php echo $var2; ?&gt;&lt;/p&gt; </code></pre> <p>would print these values out:</p> <pre><code>text1 1000 </code></pre> <p>so what i want to do is some php and jquery that would do these things:</p> <p>if $var1 equals text1 then do one of these 2 on the 1st ul list. doesn't matter which:</p> <pre><code>&lt;li class="active"&gt;&lt;a href="javascript:void(0)"&gt;text1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)" class="active"&gt;text1&lt;/a&gt;&lt;/li&gt; </code></pre> <p>if $var1 equals text2 then the second list item on the 1st ul list should get active class on the "li" or "a".</p> <p>if $var1 equals text3 then the third list item on the 1st ul list should get active class on the "li" or "a".</p> <p>if $var2 equals 500 then the first list item on the 2nd ul list should get active class on the "li" or "a".</p> <p>if $var2 equals 1000 then the second list item on the 2nd ul list should get active class on the "li" or "a".</p> <p>if $var2 equals 1500 then the third list item on the 2nd ul list should get active class on the "li" or "a".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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