user1364684
user1364684

Reputation: 800

jQuery code doesn't work correctly in Chrome & IE

I have the following javascript code in a HTML document which loads Html in a div:

<script>
$(function(){
    $("#submenu a").click(function(){
        var page = this.hash.substr(1);
        $.get(page+".html",function(gotHtml){
            $("#contenedorprincipal").html(gotHtml);
        })
    });
});
</script>

In Firefox it runs perfectly, but in Chrome and IE it does not work. Any ideas or suggestions?

Upvotes: 2

Views: 565

Answers (2)

Šime Vidas
Šime Vidas

Reputation: 185933

This should work across browsers:

$(function () {
    var $content = $( '#contenedorprincipal' );

    $( '#submenu' ).on( 'click', 'a', function ( e ) {
        $content.load( this.href.split( '#' )[1] + '.html' );
    });
});

Upvotes: 0

Yaron U.
Yaron U.

Reputation: 7881

seems to me like it works in chrome... any way try this: http://jsfiddle.net/8daxU/

replace the wrapping function with (I added an alert just to show the hash - remove at afterwords)

 $(document).ready(function(){
     $("#submenu a").click(function(){
        var page = this.hash.substr(1);
        alert(page);
        $("#contenedorprincipal").load(page+".html");
     });
 });

Upvotes: 2

Related Questions