Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Data-dir value from jQuery and pass it to PHP
    primarykey
    data
    text
    <p>I'm coping with a problem I can't figure out. </p> <p>I'm creating a menu for my website where I get all the values out of te database. I have four items: "Nintendo", "Playstation", "XBOX" and "PC". Each one of them has an unique ID. When one of the items are clicked on, I want to get that unique ID back. </p> <p>With this piece of code get my values printed out on my website: </p> <pre><code>echo "&lt;ul class=\"main_menu\"&gt;"; while($names = $get_category_names-&gt;fetch_object()) { echo "&lt;li data-dir=" . $names-&gt;id . "&gt;" . $names-&gt;name . "&lt;/li&gt;"; } echo "&lt;/ul&gt;"; </code></pre> <p>The part "li data-dir = names" is not working as expected. I console.log my values in jquery but I get the same ID back, which is 1. But, when I check Firebug, I see that I do get what I want, but this should probably be because HTML counts 4 li elements: </p> <pre><code>&lt;li data-dir="1"&gt;Nintendo&lt;/li&gt; &lt;li data-dir="2"&gt;Playstation&lt;/li&gt; &lt;li data-dir="3"&gt;Xbox&lt;/li&gt; &lt;li data-dir="4"&gt;PC&lt;/li&gt; </code></pre> <p>This is my jquery code:</p> <pre><code>$(document).ready(function() { var main_menu = $('ul.main_menu'); var sub_menu = $('ul.sub_menu'); sub_menu.hide(); var find_li = main_menu.find('li'); main_menu.on('click', function() { //sub_menu.fadeIn(200); find_li.data('dir'); console.log(find_li.data('dir')); }) }); </code></pre> <p>Can anybody point me to the right direction?</p> <p>Thanks a bunch. </p> <p>Edit: The solution to this question is below. I did not understand my code good enough to look at the right places. </p>
    singulars
    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