Chris Chris - 5 months ago 26x
Javascript Question

Get expanded attribute JQuery

I got this code snippet:

onAfterRendering: function() {
//#oTree-TreeCont: oTree -> ID des Tree, -TreeCont -> Konstante die den Content Bereich anspricht
$('#oTree-TreeCont ul li').click(function(){
var $aria = $(this).attr("aria-expanded");
if($aria){ //Element wurde aufgeklappt
var clickedNode = $(this).attr("id"); //Erfrage ID
//Lade alle Childs der 'clickedNode'


I want, that if the Tree (SAPUI5) is expanded a method should load the child elements of this node. The problem is, it alerts "true", but also "false".

Why could this happen? This part
if($aria){ }
should test if the value is true, but also when it is false, the body of the
statement is executed, why?

Thanks for every help:)


Because currently the attribute value is treating as a string value, not the boolean value. You need to check like this,