Reputation: 11
i have a problem in joomla 1.5.18. i'm trying to get text from an element using for instance
var divContent = $$('#myDiv').get('text');
but each time i get the error, in chrome: Uncaught TypeError: Object #<HTMLDivElement>
has no method 'get'; in firefox: divContent.get is not a function. why i'm getting this error?
Upvotes: 1
Views: 673
Reputation: 2159
You can also (and should) upgrade your Joomla to the latest version (security fixes, etc) and I believe it was about version 1.5.20 they included a newer version of mootools right out of the box (also there is a plugin for mootools upgrade you can enable). I believe the version included out of 1.5.20 is like 1.2.5 or something...
That may help!
Upvotes: 0
Reputation: 11
even following samples in mootools i get the same.
i know how to do it for each object in the collection. i got doing $$('.') and using the "each" method:
$$('p.classname').each(function (el){
el.addEvent('click', function() {
var txt = el.get('text');
...
});
});
and obviously i add the function onto domready. i don't use jquery 'cause mootools & jquery stops the events each one... -i tried once & what i needed didn't work- and i wish to use all joomla resources including mootools.
checking the version in mootools.js it says 1.13 (?)
Upvotes: 1
Reputation: 26165
not sure which version of mootools comes in joomla 1.5.18, it may be 1.2.5. if so, .get
should work but not as you expect it to.
You are probably a jquery user, used to $("#myid")
and find that the only way to get similar results with the # in there in mootools is via document.getElements
, aka, $$
.
the problem is, to get a single item by id in mootools, you actually do document.id("mydiv")
or even $("mydiv")
. $$("#mydiv")
will actually return a COLLECTION of elements with a single member, so [obj]
, so the real element is $$("#mydiv")[0]
.
if you apply a .get
method to a COLLECTION, the getter normally iterates via a .each through all members and performs the get individually. it will return a new array member for each member of the collection - i.e. ["innertext"];
- though there should be a method for the collection, make sure that the element is there, it's in domready
/ onload
and it's a unique id.
Still, I'd swap to using the $("mydiv").get("text")
, it ought to be fine. This is all all too common assumption of jquery users that don't read the manual, in my experience. It results in bad and un-performant code due to all the .each
iterations mootools has to silently do to work with the collection for you. Just saying.
Upvotes: 0