Feature supporting jQuery DOM elements
Feature supporting jQuery DOM elements
jpb
Posts: 3Questions: 0Answers: 0
When writing a feature plug-in, I don't seem able to create a DOM element using jquery. The code fails out during the initial creation of my object with the error: NOT_FOUND_ERR dom exception 8. This seems to be caused by returning a jquery object instead of a native javascript DOM object.
I originally defined my main object like:
[code]$(')
.addClass('ClassFilter')
.append($('')
.attr('id', 'ClassFilter-menu'));[/code]
However, this provided the error as seen above. So, on a hunch, I redefined using pure javascript:
[code]this.dom.wrapper = document.createElement('div');
this.dom.wrapper.className = 'ClassFilter';
var menu = document.createElement('div');
menu.setAttribute('id', 'ClassFilter-menu');
this.dom.wrapper.appendChild(menu);[/code]
And everything adds into the DOM correctly.
So, when I step through the code, I realize this fails because of the .appendChild( ntmp ) statement in dataTables.
I understand that my code may not be as efficient as pure javascript, but in the long run, does that really matter? There are such a minimal amount of feature extras added in mine, and probably anyone's projects that the realized time difference is most likely next to nothing. The result is sacrificing the readability of code for efficiency in execution. I prefer readability, as it lends itself to maintainability.
If you can see another way that I could do what I would like to, without modification to dataTables, I would appreciate the help very much.
Thank you,
Jonathan
I originally defined my main object like:
[code]$(')
.addClass('ClassFilter')
.append($('')
.attr('id', 'ClassFilter-menu'));[/code]
However, this provided the error as seen above. So, on a hunch, I redefined using pure javascript:
[code]this.dom.wrapper = document.createElement('div');
this.dom.wrapper.className = 'ClassFilter';
var menu = document.createElement('div');
menu.setAttribute('id', 'ClassFilter-menu');
this.dom.wrapper.appendChild(menu);[/code]
And everything adds into the DOM correctly.
So, when I step through the code, I realize this fails because of the .appendChild( ntmp ) statement in dataTables.
I understand that my code may not be as efficient as pure javascript, but in the long run, does that really matter? There are such a minimal amount of feature extras added in mine, and probably anyone's projects that the realized time difference is most likely next to nothing. The result is sacrificing the readability of code for efficiency in execution. I prefer readability, as it lends itself to maintainability.
If you can see another way that I could do what I would like to, without modification to dataTables, I would appreciate the help very much.
Thank you,
Jonathan
This discussion has been closed.
Replies
[code]
$('')
.addClass('ClassFilter')
.append($('')
.attr('id', 'ClassFilter-menu'))[0];
[/code]
i.e. add the `[0]` at the end.
However, yes, DataTables does need to play nicer with jQuery when nodes are expected.
Allan