setAttribute not working..!

in Script development
Subscribe to setAttribute not working..! 5 posts, 3 voices



ms98 Scriptwright
FirefoxWindows

function xqr(e){
  var ATTR = function (attr, value){ return this.setAttribute(attr, value); };
};
var a = 'tree';
xqr(document.getElementById(a)).ATTR('style', 'cursor: pointer;');

i know i can use: document.getElementById(a).setAttribute('style', 'cursor: pointer;');
but can the above code works ....?

thanks..

 
devnull69 Scriptwright
FirefoxWindows

No, it can't

When you use xhr().ATTR() you are expecting the function xhr() to return something that has a property/method .ATTR() ... but your code doesn't do that. All you do inside your xhr() function is create a local variable called ATTR which holds a function reference to an anonymous function that will never be called.

Can you tell us what you actually wanted to achieve?

 
ms98 Scriptwright
ChromeWindows

thanks for your respond...
and sorry for my late,

what i'am trying to achieve:
as you know jquery...
you know you can edit element's attribute by using: example: $('a').attr('href', '#');
ok, im trying to make a function can edit element's attribute
like this: example: xqr('a').ATTR('href', '#');

sorry for my bad english

 
Couchy Scriptwright
ChromeX11

http://perfectionkills.com/whats-wrong-with-ext...

Better to just type out the extra 8 letters.

 
ms98 Scriptwright
ChromeWindows

thanks a lot (Couchy)
it's worked