Jquery load png image strange characters

325
March 18, 2017, at 07:09 AM

Help me please, when load image with jquery Im getting strange charachters like this.

�PNG  IHDR���X��sBIT|d� pHYs � �B(�xtEXtSoftwarewww.inkscape.org��< IDATx��wxUE��?�B M: H" *��AE��`})� � ����꺫��kaAw���X@�,]Ŋ��D:�^" $��?�ܛ���$�\r3��'s���=�{��(�b�'*��X�f�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,�@,b�p��J���} �MDN�b�,g�^ @ ��_�T&�=0xVDN�R�,aF�t@)�p����9�r 

Here is my Jquery code

  $("#load").on('click',function(){
        //alert("okk");
        $("#wrapper").load('assets/img/logo.png');
    });

What should I do?

Answer 1

The jQuery load method (as seen in the docs http://api.jquery.com/load/) loads data as HTML, which isn't what you want to do. In order to view the PNG as an image, you should add the link as a the src attribute to an image tag. So, add an ìmg tag inside your #wrapper element and alter your jQuery as follows:

$("#load").on("click", function() {
    $("#wrapper img").attr("src", "assets/img/logo.png")
});
READ ALSO
Hover event not triggering properly in MS Edge

Hover event not triggering properly in MS Edge

I'm working on a pretty big project and have managed to get everything working on most all browsers except for MS EdgeNo supprise there but I really need this hover effect to work

460
Angular Clicking on Text to show div tag

Angular Clicking on Text to show div tag

I was wondering how to accomplish this with Angular as it seems that ng-click is something to use, then ng-model seems like that could be used

367
Autobahn JS Subscription management

Autobahn JS Subscription management

I am setting up a blog between our clients and us so they can have a space to talk about the different commercial transactions (each commercial transaction has a reference number and has it's own information)

557
I cannot change the value of a dynamically populated select using JQuery

I cannot change the value of a dynamically populated select using JQuery

I dynamically populate a select with the data coming from a DB

221