views:

41

answers:

1

This is my code:

$("#multimedia-tabs #"+response.currenttab+" #"+response.currenttab+"div").append(divHtml);

Where divHtml has the html li tags

It works fine in FF and chrome but not in IE7 and 8 :(

Tried many alternatives available on this site but no joy!

Please help

$(document).ready(function() {
    $("#next").live('click', function(){getMultimedia($(this).attr('page'), $(this).attr('url'));});
    $("#previous").live('click', function(){getMultimedia($(this).attr('page'), $(this).attr('url'));});
    $("a.page").live('click', function(e){getMultimedia($(this).attr('page'), $(this).attr('url'));});
});

function displayPage(response){
    response = JSON.parse(response);
    $("#multimedia-tabs #"+response.currenttab+" #"+response.currenttab+"div").html('');
    var divHtml = '';
    for(var i in response.page){
            divHtml += '<li><a class="medialink" href="'+response.page[i].MedUrl+'">'+response.page[i].MedUrl+'</a></li>';
    }
    divHtml += '';
    var target = response.currenttab+'div';
    $("#"+response.currenttab+"div").append(divHtml);
    updatePageLinks(response.currentPage, response.currenttab);
}

function updatePageLinks(page, currenttab){
    $("#multimedia-tabs #"+currenttab+" #previous").attr('page', page-1);
    $("#multimedia-tabs #"+currenttab+" #next").attr('page', page+1);
}

function getMultimedia(page,url){
    var url = url + "/page/" + page;
    $.post(url,
              {"format" : "json"},
              function(data){
                      displayPage(data);
              }, 'html');
    return false;
}
+1  A: 

It looks like you have multiple of the same ID. IE won't tolerate this like other browsers will in some cases...it is invalid HTML. You need to give your elements unique IDs.

Also, you can then shorten your selector, since IDs should be unique to:

$("#"+response.currenttab+"div").append(divHtml);
Nick Craver
Hi NickThanks for your reply. I've tried shortening my selector and made sure that id's are not repeated. Checked with HTML Tidy too! It still doesn't work!
Vishal
@Vishal - In that case, post the html!
Nick Craver
Can someone help please?
Vishal
I have added my Javascript code in the main question. Thanks
Vishal
@Vishal - html != javascript :) If you're saying the selector doesn't work, then it's not matching the html...without the html that makes it pretty hard to figure out what's wrong :)
Nick Craver