AlexGH AlexGH - 4 months ago 23
Javascript Question

Get JQuery data- that contains value with spaces

I have two functions: in the first one, I'm setting the

attribute using JQuery:

"<input type=\"image\" + " data-file_name=" + result.fileName/>"

Which works great, but when I'm trying to retrieve that value from the second function if the
data-file_name value
contains spaces I just get the first word(for example if
data-file_name= "The book blue"
I just get
, if
data-file_name = "Red Dragon"
I just get on the second function
it stops when it find an space... )
This is the way I'm retrieving the value in the second function:

var fileName = $(this).data("file_name");

fileName variable
will not get the real value because it doesn't include anything behind the spaces, which way should I use to retrieve the value complete including spaces and everything?


There is a concatenation problem.

Replace with this

"<input type=\"image\" data-file_name=\"" + result.fileName + "\" />"