Newbie question: Referring to element by class
Hi,
Can anyone offer me some explanation as to selecting an element by class name? In an online example this template code is give for a button element:
[code]
<button data-catid="{{category.id}}" data-title="{{ result.title }}" data-url="{{ result.link }}" class="rango-add btn btn-mini btn-info" type="button">Add</button>
[/code]
So there is no element id, but there is a class name of
"rango-add btn btn-mini btn-info". The example jquery ajax code is given as follows:
[code]
$
(
'.rango-add'
).
click
(
function
(){
var
catid
=
$
(
this
).
attr
(
"data-catid"
);
var
url
=
$
(
this
).
attr
(
"data-url"
);
var
title
=
$
(
this
).
attr
(
"data-title"
);
var
me
=
$
(
this
)
$
.
get
(
'/rango/auto_add_page/'
,
{
category_id
:
catid
,
url
:
url
,
title
:
title
},
function
(
data
){
$
(
'#pages'
).
html
(
data
);
me
.
hide
();
});
});
[/code]
To me the event handler is looking out for the class "rango-add" which surely is different to
"rango-add btn btn-mini btn-info".
Why does this work?
Thanks,
Andy