I need to retrieve attribute value of <div>
tag using jquery
This is my html code where $_GET['availabel_table']
and $_GET['number-of-person']
are coming from url
<div id=main_menu_data class="grid_21 alpha prefix_1" availabel-table="<?php echo $_GET['availabel_table'] ?>" number-of-person="<?php echo $_GET['number_of_person'] ?>" >
Jquery code
var availabel_table = $("#main_menu_data").attr("availabel-table");
var number_of_person = $("#main_menu_data").attr("number-of-person");
but value is not coming in these variables. What i am doing wrong.
Missing quotes on the DIV's id?
<div id="main_menu_data" class="grid_21 alpha prefix_1" availabel-table="<?php echo $_GET['availabel_table'] ?>" number-of-person="<?php echo $_GET['number_of_person'] ?>" >
This:
<div id=main_menu_data
should be this:
<div id="main_menu_data"
You should set your data values with with valid data attributes, your code would be something like:
<div id="main_menu_data" class="grid_21 alpha prefix_1" data-available-table="<?php echo $_GET['availabel_table'] ?>" data-number-of-people="<?php echo $_GET['number_of_person'] ?>" >
then to access this data, you can use the jQuery data function:
var available_table = $("#main_menu_data").data("available-table");
var number_of_people = $("#main_menu_data").data("number-of-people");
var numberPerson= $('#number_of_person').val();
var availabelTable= $('#availabel_table').val();
of course that you should be declare thats variables in html