0

I have my JS code as below;

var editable = isNameEditable(this.get("status"));
return "<div class='editableTxt' name='myNameFld' data-editable=" + editable + "'">" + this.get("name") + "</div>";

The function isNameEditable just returns boolean value (true/false)

I then append it to my div using data-editable attribute.

I use the above value for comparision later and use below code;

if ($(this).attr('data-editable')) 

However, the appended value becomes a string ("true"/"false") and hence the above condition does not work as expected.

Is there any way by which I can append a boolean value, so that I do not have to change my comparison i.e.

if ($(this).attr('data-editable')) 
Alex Char
  • 32,295
  • 8
  • 49
  • 69
copenndthagen
  • 46,750
  • 95
  • 274
  • 417

1 Answers1

4

String boolean values to boolean conversion methods are explained in this post:

How can I convert a string to boolean in JavaScript?

For example, you can use

if(!!$(this).data('editable'))

to check if the div is editable.

Community
  • 1
  • 1
Taha Paksu
  • 14,871
  • 1
  • 44
  • 74