Skip to content Skip to sidebar Skip to footer

Prepend/append Don't Work (opera, Safari, Chrome)

Comarades, I tried using the append and prepend (), but none of the controls work. Could anyone help me? In Internet Explorer and Firefox works. The Code:

Solution 1:

Well one thing that looks odd to me is that you're adding <img> tags with "id" values that exactly duplicate other "id" values in other tags. Maybe WebKit doesn't like that; it's definitely a bad thing to do.

Try a change like this:

objDest.append('<img id="' + strDestino + '_img" src="' + objComp.val() + '"');

Also it looks to me as if you're forgetting the ">" at the end of your elements! Should look like this:

objDest.append('<img id="' + strDestino + '_img" src="' + objComp.val() + '">');

(If your DOCTYPE is XHTML you should use "/>" of course, but yours is "html".)

Solution 2:

These will never be null. They will always contain a jQuery object (even if it is empty of elements).

if((objComp!=null)&&(objDest!=null))

You should test using the length property.

if ((!objComp.length) && (!objDest.length))

Also, as far as I can tell, you are creating a new element that has the same ID as the existing strDestino element.

objDest.append('<img id="' + strDestino + '" src="' + objComp.val() + '"');

You can't have 2 elements with the same ID.

Solution 3:

Source Working in: Opera, Safari, Chrome, IE, Mozilla.

selEstrutura = function(strComponent, strDestino)
{
$('#' + strDestino + ' img').remove();
$('#' + strDestino).append('<img id="' + strDestino + '_img" src="' + $('#' + strComponent).val() + '">');
if ((strDestino == 'eixoTracionado1') || (strDestino == 'eixoTracionado2'))
{
    $('#eixoEstruturaPt1 img').remove();
    $('#eixoEstruturaPt1').append('<img src="estrutura_semrodas.gif" alt=""/>');

    $('#eixoEstruturaPt2 img').remove();
    $('#eixoEstruturaPt2').append('<img src="estrutura_semrodas.gif" alt=""/>');
}
} 

I made the changes suggested by friends, but in some browsers was not working. After some testing, I discovered that the method ". Trim ()" was not working properly.

Thanks for the help of all.

Solution 4:

Had the same problem. A php script generated a json that was passed to jquery.each(). Firefox showed rows in correct order while chrome displayed them in reverse.

The problem was caused by object keys. Chrome sorted the array using the keys before foreach. The solution in my case was to use an auto incremented value as key instead of my old, revision number key, which was in reverse.

Post a Comment for "Prepend/append Don't Work (opera, Safari, Chrome)"