$('.parent').click(function () {
var li = $('li').next();
var target_url = $('.ul_1 > ' + li + ':eq(0) > a').attr('href');
alert(target_url);
if(target_url!=undefined) window.location.href=target_url;
return false;
});
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.selected {color:red; background-color:yellow;}
</style>
<script type="text/javascript">
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function(){
var id=getParameterByName(id);
// to test this, uncomment below, or save as index.htm, open it browser, then add ?id=2 to url and refresh the page, you will see class will change, then play with id=1, id=2, id=3, id=4
// id=2;
var a = $('#menu a[href*="id='+id+'"]')[0];
$(a).parent().addClass("selected");
});
</script>
<ul id=menu>
<li><a href="index.php?id=1">A</a>
<li><a href="index.php?id=2">B</a>
<li><a href="index.php?id=3">C</a>
<ul>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.selected {color:red; background-color:yellow;}
</style>
<script type="text/javascript">
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function(){
var id=getParameterByName("id");
var a = $('#menu a[href*="id='+id+'"]')[0];
$(a).parent().addClass("selected");
});
</script>
<ul id=menu>
<li><a href="?id=1">A</a>
<li><a href="?id=2">B</a>
<li><a href="?id=3">C</a>
<ul>
$('.parent').click(function () {
//var parent_element=$(this).parent();
var target_url=$(' .ul_1 > li:eq(0) > a').attr('href');
alert(target_url);
if(target_url!=undefined) window.location.href=target_url;
return false;
});
<script type="text/javascript">
$(function(){
$('.parent').click(function() {//alert(this.href);
var a = $('ul li:first a', $(this).parent());
if ($(a)){
alert($(a).attr("href"));
window.location.href=$(a).attr("href");
};
return false;
});
});
</script>
http://stackoverflow.com/q