SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face In need of a little help

    I have made a little script which purpose is to check for a part of a string inside a url and do substitute that string/url.

    But i get a unexspected object error
    What am i doing wrong?

    Code:
    jQuery(document).ready(function($) {
    
    $('#menu a').language();
    
    }); 
    
    (function($) {
    
    $.fn.language = function() {
     $(this).each(function() {
    	 if(this.attr("href").indexOf('about') > 1) {
    		 this.attr("href","http://www.somelink.com");
    	 }
    });
    
    }
    
    })(jQuery);

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ended doing something like this. It works but im not sure its the right way to do it.

    Code:
    (function($) {
    
    $.fn.language = function() {
    	
    var list = Array('anchortext 1','anchortext 2','anchortext 3','anchortext 4');
    var url  = Array('link 1','link 2','link 3','link 4');
    
    $(this).each(function(i,string) {
      if( $(this).text() == list[i] ) { 
        $(this).attr("href",url[i]); 
      }
    });
    
    }
    
    })(jQuery);


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •