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,879
  • 9
  • 49
  • 70
copenndthagen
  • 49,230
  • 102
  • 290
  • 442

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
  • 15,371
  • 2
  • 44
  • 78