www.webdeveloper.com
Results 1 to 4 of 4

Thread: Function parameter do not work

  1. #1
    Join Date
    May 2013
    Posts
    1

    Function parameter do not work

    Hello,

    sorry in advance for this studipe question, but I'm kind of new to js so here goes:
    I've got this two methods:
    PHP Code:
    function register() {
        for(var 
    1<= 6i++) {
            $(
    "#nl_" i).click(function(event) {
                 
    // does not work
                
    activate(document.getElementById("nl_" i), document.getElementById("ni_" i));
                 
    // works fine
                
    $(document.getElementById("nl_2")).attr("class""navi_link_active"); 
            });
        }
    }

    function 
    activate(navi_linknavi_img) {
        $(
    navi_link).attr("class""navi_link_active");
        $(
    navi_img).attr("class""navi_img_active");

    My activate method does not work. In contrast the test method with "nl_2" does work fine. I can't find the mistake I made.

    Thanks you!

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    paste your full code.

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    Code:
    function register(){
    $('*[id*=nl_]').each(function(){
    var this_num=new Number($(this).attr('id').substring(3,$(this).attr('id').length));
    if(0 < this_num && this_num <=6){
    $(this).click(function(){
    $(this).attr('class','navi_link_active');
    $('#ni_'+this_num).attr('class','navi_img_active');
    });
    }
    });
    }
    
    $(document).ready(function(){
    register();
    });
    live demo

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    Code:
    function register(){
    $('*[id*=nl_]').each(function(){
    var this_num=new Number($(this).attr('id').substring(3,$(this).attr('id').length));
    if(0 < this_num && this_num <=6){
    $(this).click(function(){
    $(this).attr('class','navi_link_active');
    $('#ni_'+this_num).attr('class','navi_img_active');
    });
    }
    });
    }
    
    $(document).ready(function(){
    register();
    });
    change 6 to the number of links you have or count them on runtime more accurately.

    more simpler version
    Code:
    $(document).ready(function(){
        $('*[id*=nl_]').live('click',function(){
            $(this).attr('class','navi_link_active');
    	    $('#ni_'+this_num).attr('class','navi_img_active');
        });
    });

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles