Jump to content

getting a custom attribute? passing to a function without a name?


kthxbai2u

Recommended Posts

Ok, I am not a JavaScript programmer, although I have been picking alot of things up...

 

I am using PHP, and Ajax right now, and I am working on a menu. I am trying to assign a custom value to the <.a.> tag like

 <a href='ignorethefile.php' myattribute='page_location'>

and then retrieve it within JScript, and pass it through a wack load of functions that dont have names... 

 

Assume the onclick calls this function below already

 

function clickMenuLink() {

     
    		var LoadMsg = 'Loading Content...';
    		disableMenuLinks();
        
        if(!$(this).hasClass("current")) {
        
        var _Href = $(this).attr('href');
        var pg = $(this).attr('myattribute');
        
        $("<div id='loading'> "+LoadMsg+' </div>').appendTo('body').fadeIn('slow',function(pg){
            
            $.ajax({
                type:   'POST',
                url:    "/tempsite/index.php/" + pg + "/",
                data:   "ajax=1&nohref=1",
                dataType:   'html',
                timeout:    5000,
                success: function(d,s,pg){
                        $('#loading').fadeOut('slow',function(){
                            $(this).remove();
                            $('#main').slideUp('slow',function(){
                                    $(this).html(d).slideDown('slow');
                                    
                                    ajaxifyContentLinks();

											enableMenuLinks(pg);

                                });
                            });
                        },
                error: function(o,s,e){
                            window.location = _Href;
                        }
            });
            
            
        }
        );
        }
        return false; 
   
  
}

 

but it seems that the value is not being retrieved from the A tag....

 

Anyone know what I did wrong?

Oh sorry, i neglected to mention I am using CodeIgniter..... That is a url to send the browser to after getting the custom attribute. My only concern is that I cant get that custom attribute... That attribute defines the page name...

 var pg = $(this).attr('myattribute');

 

dont even get my attribute... Anyone know how to do this? I have been googling all day on this one thing...

 

I even tried changing myattribute to id and then tried $(this).id and $(this).attr('id') nothing works... I been getting "undefined" when i pipe that to alertbox()

Personally i use

document.getElementsByID('test').getAttribute('myattribute');

so try

var pg = $(this).getAttribute('myattribute');

 

I tried

$(this).getAttribute('myattribute');

but it returns undefined...

 

And I am trying to get the ID, or the custom attribute... I dont know what the ID is unless I use $(this).id or whatever you use to get the id...

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.