Jump to content

extending methods


The Little Guy

Recommended Posts

I have this:

JSLive.extend = function(destination, source) {
    for (var property in source) {
        if (source.hasOwnProperty(property)) {
            destination[property] = source[property];
        }
    }
    return destination;
}
JSLive.prototype.item = function(itm){
if(JSLive.is_string(itm)){
	if(itm.match(/^#/)){
		return document.getElementById(itm.replace(/^#/, ''));
	}else{
		if(this.getElementsByTagName){
			return this.getElementsByTagName(itm);
		}else{
			return document.getElementsByTagName(itm);
		}
	}
}else{
	return itm;
}
}
JSLive.prototype.att = function(attribute, setting){
alert(this);
}

 

I want to use it like this:

<p>
<a href="http://google.com" id="link">Google.com</a>
</p>
URL: <input type="text" id="url" /><br />
<input type="button" value="Change" onclick="live.item('#link').att('href', 'http://yahoo.com')" />

 

basically what that does is take the link, and modify the href attribute, but I can not get it to work, I am getting the following error:

Uncaught TypeError: Object http://google.com/ has no method 'att'

 

Any suggestions on what I am doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/226159-extending-methods/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.