www.webdeveloper.com
Results 1 to 4 of 4

Thread: anonymous functions, using .html(array[i]), not working

  1. #1
    Join Date
    Mar 2010
    Posts
    281

    anonymous functions, using .html(array[i]), not working

    I'm really stumped on this. it may have to do with javascript closures..?

    hope i can explain...i have an array of 22 phoenician letters, (strange i know).

    and there are 22 corresponding divs with numeric id's.
    using jQuery i set mouseover & out event handlers to hide/show another div that contains the rolled over letter. i'm trying to use jQ's .html()
    to put the content in the div like so.

    .html(pLetters[i]), the counter i is not working, if i write .html(pLetters[1]) it will display the single letter, (thought not what i want.)
    PHP Code:
    var pLetters = [')''b''g''d''h''w''z''x''+''y''k''l''m''n''s''(',
     
    'p''c''q''r''$''T'];
    $(
    document).ready(function() {

            for(
    i=0;i<22;i++) {
            
    //alert(pLetters[i]); this test works..
                
    $('#p'+i).mouseover(function() {
                $(
    '#p-letter-container').fadeIn('fast');
                $(
    '#p-letter-container').html(pLetters(i)); //this is not working but doesn't throw an error either..?

            
    });    
                $(
    '#p'+i).mouseout(function() {
                $(
    '#p-letter-container').fadeOut('fast');
                $(
    '#p-letter-container').html(); //removes the HTML from the div
                    
    });    
            }
        }); 

  2. #2
    Join Date
    Jul 2011
    Posts
    127
    Can you show your HTML?

    $('#p-letter-container').html(); //removes the HTML from the div
    This line will return (not remove) HTML from the div. To remove HTML you have to write
    Code:
    $('#p-letter-container').html('');

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    $('#p-letter-container').html(pLetters(i));

    this is the syntax for function not an array; use []

  4. #4
    Join Date
    Mar 2010
    Posts
    281
    thanks for the replies guys

    This line will return (not remove) HTML from the div. To remove HTML you have to write
    Code:
    $('#p-letter-container').html('');
    , got it thanks,

    PHP Code:
    [I]$('#p-letter-container').html(pLetters(i)); [/I], 
    that was an error in my post. i actually have it coded with brackets. guess i was trying anything and everything at one point.

    i don't normally post stuff in progress but will make an exception.
    please know, this site is def underconstruction. i did not design, just building it.

    http://www.aboveourblueworld.com/staging3/index-w6.html

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