javascripttitlespacedecodeuricomponent

title does not work with decodeURIComponent and space


I am trying to write with javasctipt line of code, but decodeURIComponent ignore everything after %20 (space). How to solve this?

$(".intome").append($('<img title=' + decodeURIComponent(filename) + ' src=' + dir + ' />'));

Instead of:

<img title:"some text" src="img.png">

I am geting this:

<img title:"some" text src="img.png">

JSFiddle: https://jsfiddle.net/emnLy1t5/9/

I am an absolute newbie so I would really appreciate any advice. Also I am not native english speaker, so I am sorry for my bad english...


Solution

  • Wrap the output of decodeURIComponent(filename) in quotes.

    $(".intome").append(
        $('<img title="' + decodeURIComponent(filename) + '" src=' + dir + ' />')
    );