سؤال

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!

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top