Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery/Javascript syntax

I am trying to figure out what the below syntax do. It's code from Bootstraps popover.

//title is a string
$tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)
                           ^                                                 ^
                       What does this symbol mean?                    Whats happening here?
like image 419
River Avatar asked Dec 13 '22 03:12

River


1 Answers

Let's break it up:

$tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)

It can be broken down into this:

var found = $tip.find('.popover-title');
found[$.type(title) == 'object' ? 'append' : 'html'](title);

And more:

var found = $tip.find('.popover-title');

if ($.type(title) == 'object') {
  found['append'](title);
} else {
  found['html'](title);
}

A little more:

var found = $tip.find('.popover-title');

if ($.type(title) == 'object') {
  found.append(title);
} else {
  found.html(title);
}
like image 76
Blender Avatar answered Dec 17 '22 23:12

Blender