Closed gabyshev closed 11 years ago
I could be wrong about this, but it looks like the hash generator is called by this code in tocify.js
:
hashValue = hashGeneratorOption(self.text(), self);
It looks like the first argument is just the text content of the header, but the second argument is the element. If you change your code to
hashGenerator: function(text, element) {
return element.getAttribute('id');
}
it might work.
@rlord is correct that the first argument is the text content of the header and the second argument is the element.
I've tried function(text, element)
but error is the same.
$(function() {
$("#toc").tocify({
hashGenerator: function(text, element) {
return element.getAttribute('id');
}
});
});
Uncaught TypeError: Object [object Object] has no method 'getAttribute'
That's probably because the element
argument is a jQuery object. Try this:
$(function() {
$("#toc").tocify({
hashGenerator: function(text, element) {
return element[0].getAttribute('id');
}
});
});
@gfranko thanks a lot. Now, it looks perfect.
I'm trying to generate hash with hastags like "#feature-id-456".
I've tried this
But it throws an error:
Uncaught TypeError: Object Тесты проекта billing has no method 'getAttribute'
Also I've tried
element.id
, but get errorUncaught TypeError: Cannot read property 'top' of undefined
How can I do this?