0

I've a big project where there still exist some MS ajax functions used all over the project. I could rewrite them using jquery but for now that would take to much time.

However we now using jquery for every new functionality.

Take a look at this:

    $.each($("a[xonclick]"), function (index, value) {
            EnableButton(value);
        });
    function EnableButton(btn) {
        ...
        var xonclick = btn.getAttribute("xonclick");
        ...
    }

Off course i get the javascript error:

getAttribute is not a function

I know i could use btn.attr("xonclick"); but that's not an option as i mentioned before.

Is there some jquery function that gives me a MS ajax object for a jquery object? I could then use that object and pass it to the enableButton function.

UPDATE: JSFiddle: http://jsfiddle.net/wsYCJ/1/

I hope i explained it well and someone of you knows a solution for this.

Thanks!

ThdK
  • 9,916
  • 23
  • 74
  • 101
  • Sorry, I don't understand what you're asking. `$.each($("a[xonclick]"))` (as well as `$("a[xonclick]").each()`) will feed DOM elements to `EnableButton()`, and DOM elements do support the `getAttribute()` method. I also don't know how AJAX would relate to your question... – Frédéric Hamidi Jul 13 '12 at 12:44
  • Hello, the $get(id) is a member of the Microsoft Ajax client library (http://msdn.microsoft.com/en-us/library/bb383788.aspx) I'll create a fiddle to demonstrate. thanks – ThdK Jul 13 '12 at 12:55
  • Yup, I know `$get()` is part of ASP.NET AJAX, but I cannot find such a call in your question. Did you end up posting the code you actually wanted to post? :) – Frédéric Hamidi Jul 13 '12 at 12:57
  • Hi, on all other places i use something like this: EnableButton($get('myId')); And the the getAttribute Function is working. But when i pass the jquery object, it fails.. I've updated my question with a fiddle showing the problem. – ThdK Jul 13 '12 at 13:10

1 Answers1

1

As you said in the comments, $get() is part of the ASP.NET AJAX library and returns an augmented DOM element (actually an instance of Sys.UI.DomElement).

On the other hand, jQuery's $() function returns a jQuery object that wraps one or more DOM elements. jQuery objects do not support getAttribute(), DOM elements do.

You can use get() or the indexer syntax to get an actual DOM element from a jQuery object. In other words, you have to write:

function buttonClicked() {
     getAttr($("#test")[0]);
}

Instead of:

function buttonClicked() {
     getAttr($("#test"));
}

You will find an updated fiddle here.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Hello, this will indeed fix the fiddle :) But.. when using jquery each function will pass already a single domElement. I don't know what i did wrong before, but this fiddle (http://jsfiddle.net/wsYCJ/3/) with "each" works now correctly using getAttribute. Thanks for your help, you finally encouraged me to try getAttribute again :) – ThdK Jul 13 '12 at 13:42