Reputation: 15594
I'm working with JQuery FullCalendar
and I just tried to use a call back function eventRender
and call the element.getAttribute()
as in the code sample.
but it says Uncaught TypeError: Object [object Object] has no method 'getAttribute'
Why is this happening ?
this Standard Properties and Methods on HTML elements does not work with the element
object. As it the FullCalendar documentation says element is a newly created jQuery <div> that will be used for rendering. It has already been populated with the correct time/title.
But I can't call that methods and properties on that element
Code :
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
editable: true,
events: [
{
title: 'First',
start: new Date(2014, 1, 24, 8),
end: new Date(2014, 2, 3, 8)
},
{
title: 'Second',
start: new Date(2014, 2, 3, 8),
end: new Date(2014, 2, 10, 8)
}
],
eventRender: function(event, element) {
alert(element.getAttribute("id"));
},
eventAfterRender : function(event, element) {
alert(element.getAttribute("id"));
},
eventAfterAllRender: function(event, element) {
alert(element.getAttribute("id"));
}
});
});
thanks in advance..
Upvotes: 0
Views: 120
Reputation: 388436
Because element
is not a dom element reference, it is a jQuery object so you need to use .attr()
element.attr('id')
Demo: Fiddle
Or you can access the actual dom element using element[0]
or element.get(0)
Upvotes: 2