简体   繁体   中英

Get attr form <a href>

ive got a problem with getting attr from <a href> .

Got something likte this

<a href="#callback" realurl="callback.aspx">Callback</a>

And jQuery

$('#callback').bind('pageAnimationEnd', function (e, info) {

                var realurl = $(this).attr('realurl');

                if (!$(this).data('loaded')) {
                    $(this).append($('<table border=0 width="100%" height="100%"><tr width="100%" height="100%"><td>Wczytuję...</td></tr></table>').
                        load(realurl, function () {
                            $(this).parent().data('loaded', true);
                            $('#ParentTest').html("test");
                        }));
                }
            });

And im getting all the time undefined from $(this).attr('realurl').

This does not work the way you intend.

$('#callback')

finds the elements having id="callback" . So if your HTML would be like:

<a id="callback" href="#callback" realurl="callback.aspx">Callback</a>

it would work. Alternatively, you can leave the html as is and write:

$("a[@href='#callback']")

instead. This should get all a elements having the href attribute set to #callback

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM