I have a list of item wrapped in UL and I want to make the element selected be active on another page with sub-menu opened if there is any.
jQuery(document).ready(function(){
$(window).load(function() {
$("#task .c-task-menu #menu-task-menu").addClass("task-menu");
$(".task-menu li.grand-parent > a,.task-menu li .sub-menu li.parent-menu > a").addClass("menu-link");
$(' .menu-link').click(function(e) {
e.preventDefault();
});
$('.menu-link').each(function(){
$(this).attr('id','#'+$(this).text().replace(/\s+/g,'_'));
var parent_menu = $('.task-menu li.grand-parent > a').text().replace(/\s+/g,'_');
var child_menu = $('.task-menu li .sub-menu li.parent-menu > a').text().replace(/\s+/g,'_');
$(this).attr("href", "https://mystuff.com/#"+child_menu );
});
$('.task-menu li ul').css({'display':'none'});
$('ul.task-menu li').click(function () {
$('.sub-menu:visible').add($(this).find('.sub-menu:first')).toggle();
});
$('.student_team_btn').css({'cursor': 'pointer'});
$('.student_team_btn').click(function(){
$('.student_team_more').toggle();
$(this).text() === 'Learn More' ? $(this).text('Show Less') : $(this).text('Learn More');
});
$('ul.task-menu li a').click(function() {
$(this).parent().addClass('active');
$(this).parent().siblings().removeClass("active");
});
// to make the task menu on the homepage clickable
$('.home li.grand-parent ul.sub-menu li.parent-menu > a').each(function(){
//$(this).attr("href", "https://mystuff.com/task-menu/");
//$('.home li.grand-parent').uniqueId();
//$(this).uniqueId();
var grand_parent = $('.home li.grand-parent > a').text().replace(/\s+/g,'_');
var generic = $(this).text().replace(/\s+/g,'_');
$(this).attr('id',generic);
$('.home li.grand-parent > a').attr('id', grand_parent);
});
$('.home li.grand-parent ul.sub-menu li.parent-menu > a').click(function() {
var generic = $(this).text().replace(/\s+/g,'_');
$(this).attr("href", "https://mystuff.com/task-menu/#"+generic);
alert('my name');
$(".task-menu li.grand-parent > a,.task-menu li .sub-menu li.parent-menu > a").trigger('click');
});
});
});
The code above is to change the url to the url of the task-menu.
Below is the picture of the task menu.
I want the selected element be made from the first image, then it will open the task-menu and make link selected and active.
Please, any assistance will be appreciated. Thank you in advance.