Hi I have a menu like this into my website:
<div class="menu">
<p align="left" id="home" class="titolo_menu">home</p>
<p align="left" id="azienda" class="titolo_menu azienda"><br>azienda</p>
<p align="left" id="staff" class="titolo_sotto_menu azienda">staff</p>
<p align="left" id="risorseumane" class="titolo_sotto_menu azienda">risorse umane</p>
<p align="left" id="servizi" class="titolo_menu servizi"><br>servizi</p>
<p align="left" id="servizioclienti" class="titolo_sotto_menu servizi">servizio clienti</p>
<p align="left" id="prodotti" class="titolo_menu prodotti"><br>prodotti</p>
<p align="left" id="web" class="titolo_sotto_menu prodotti">web</p>
</div>
I want to check when I click an element if has a class of the old page.
I store the id of old page in my php session and retrieve after in javascript.
Example my old page id is: “azienda” (is the of the p of my menu).
I search into my menu the element that have the id “azienda” and I want to compair with the element that I have click now for example staff.
I want to compaire if my p with id”staff” contain a part of class, in this case “azienda”, with old p clicked. In this case match.
The problem is that I have two classes into my p, if there was only one isn’t a problem but with two I want to compair only the second class.
$('.titolo_sotto_menu').click(function(){
var id=$(this).attr('id');//staff
var class=$(this).attr('class');
var page=id;
old_page=actual_page;//azienda
actual_page=page;
var class_old = $('#'+old_page).attr('class');
if (class == class_old){
//do something
}
});
You can use the function element.hasClass(‘classname’) of jQuery.