JSP/javascript jQuery

[jQuery] 현재 메뉴에 따른 동적 title 만들기

도미노& 2025. 2. 19. 17:23

select 하는 메뉴 구조

const menuList = [
	{ 'menuName' : 'Login', 'menuPath' : '/login' }
	, { 'menuName' : 'Password Recovery', 'menuPath' : '/password' }
	, { 'menuName' : 'Create Account', 'menuPath' : '/register' }
];

 

일 때

 

동적으로 title 만들기

function gfnSetTitle(menuList) {
	var sRealPath = $(location).attr('pathname'); // "/login"
	
	for (var menu of menuList) {
		if (menu.menuPath === sRealPath) {
			$(document).attr("title", menu.menuName + " | 사이트명"); 
		}
	}
}