Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

href is always "undefined"

On alert I always get undefined... why ?

<script type="text/javascript">

$(document).ready(function(){
    $("#menu ul li").click(function() {
        var path = $(this).attr("href"); 
        alert (path);
        $.get(path, function(data) { $("#texte").html(data); });
        return false;
    });
});

</script>

</head>

<body>

<div id="wrapper">

<div id="menu">
  <ul>
    <li><a href="pulse/data/blocks/intro.html">Intro</a></li>
    <li><a href="pulse/data/blocks/presentation.html">presentation</a></li>
    <li><a href="pulse/data/blocks/pourquoi.html">pourquoi ?</a></li>
    <li><a href="pulse/data/blocks/forfaits.html">forfaits</a></li>
  </ul>
</div>
like image 878
menardmam Avatar asked Nov 29 '22 16:11

menardmam


1 Answers

You need to select the a tag.

var path = $('a', this).attr("href"); 
like image 150
Daniel A. White Avatar answered Dec 09 '22 18:12

Daniel A. White