www.webdeveloper.com
Results 1 to 7 of 7

Thread: Write active image title

  1. #1
    Join Date
    Dec 2009
    Posts
    51

    Write active image title

    Hi

    I have a simple drop down navigation:

    Code:
    <li><a href="#">menu 1</a>
        <ul>
             <li class"active"><img src="images/image1.png" title"image one description" alt="image one description"  />item 1</li>
             <li><img src="images/image2.png" title"image two description" alt="image two description" />item 2</li>
             <li><img src="images/image3.png" title"image three description" alt="image three description" />item 3</li>
             <li><img src="images/image4.png" title"image four description" alt="image four description" />item 4</li>
          </ul>
    </li>
    <li><a href="#">menu 2</a>
    What I want to do is write the title description of the active menu item into a div.

    Whats the best way to do this?

    Many thanks

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    $(div).text($("li .active img").attr("title"));
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  3. #3
    Join Date
    Dec 2009
    Posts
    51
    Many thanks rnd!!!

  4. #4
    Join Date
    Dec 2009
    Posts
    51
    Quote Originally Posted by rnd me View Post
    Code:
    $(div).text($("li .active img").attr("title"));
    Hi rnd me

    I have another issue relating to this question, I hope you don't mind helping/guiding me again.

    This is a section of my drop down menu
    Code:
     
    <li id="colours"><a href="#">colours</a>
      <ul>
        <li class="active"><img src="image1.png" alt="" title="White" />WHITE</li>
        <li><img  src="image2.png" alt="" title="red" />RED</li>
        <li><img  src="image3.png" alt="" title="blue" />BLUE</li>
        <li><img src="images4.png" alt="" title="orange" />GREEN</li>
    
        <li class="active"><img src="image1.png" alt="style 5" title="pink" />pink</li> //("alt" tag in div.box2 and title in div.box1)
        <li><img  src="image2.png" alt="style 6" title="purple" />purple</li>              //("alt" tag in div.box2 and title in div.box1)
        <li><img  src="image3.png" alt="style 7" title="orange" />orange</li>            //("alt" tag in div.box2 and title in div.box1)
      </ul>
    </li>
    <li  id="style"><a href="#">style</a>
      <ul>
        <li class="active"><img src="image5.png" alt="" title="style 1" />style 1</li> //("title" tag in div.box2)
        <li><img src="image6.png" alt="" title="style 2" />style 2</li>                     //("title" tag in div.box2)
        <li><img src="image7.png" alt="" title="style 3" />style 3</li>                     //("title" tag in div.box2)
        <li><img src="image8.png" alt="" title="style 4" />style 4</li>                    //("title" tag in div.box2)
      </ul>
    </li>

    What I want to do this time is store the alt tags of the last 4 links (in the 1st tab) if it is "active, but I want to store in div.box2.

    This is the code:
    Code:
      $('div.box1').text($("#colours ul .active img").attr("title"));
      $('div.box2').text($("#colours ul .active img").attr("alt"));
      $('div.box2').text($("#style ul .active img").attr("title"));
    I have another tab in my menu (also a dropdown - called style). With this one I need to write the "active" "title" into div.box2 as well:

    The code is not working together.

    The text in div.box2 is either the "alt" tag or the "title tag" - so the text is replaced.

    Is there no way to achieve this?

    Hope that made sense. I would really appreciate your help on this.

    Thanks again
    Last edited by pc_mac; 04-22-2013 at 07:34 AM.

  5. #5
    Join Date
    Dec 2009
    Posts
    51
    This works:
    Code:
      
    $('div.box1').text($("#colours ul .active img").attr("title"));
     $('div.box2').text($("#style ul .active img").attr("title"));
    and this works works

    Code:
      $('div.box1').text($("#colours ul .active img").attr("title"));
      $('div.box2').text($("#colours ul .active img").attr("alt"))


    Is there a way to get these two to work without clashing?
    Code:
     
    $('div.box2').text($("#style ul .active img").attr("title"));
    $('div.box2').text($("#colours ul .active img").attr("alt"))
    Last edited by pc_mac; 04-22-2013 at 08:38 AM.

  6. #6
    Join Date
    Dec 2009
    Posts
    51
    I went down a different route and have got it working.
    I changed the text in div.box2 using:
    document.getElementsByClassName("box2").innerHTML = "Style name"; (The alt tag in all four links is the same text)

    But out of curiosity it would be interesting to know what the solution would have been?

  7. #7
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    i'm not sure i understood everything right, but try this

    Code:
    $("#colours .active img").each(function(){
    $('div.box2').append('&nbsp;<span>'+$(this).attr('alt')+'</span>');
    $('div.box1').append('&nbsp;<span>'+$(this).attr('title')+'</span>');
    });
    
    $("#style ul .active img").each(function(){
    $('div.box2').append('&nbsp;<span>'+$(this).attr('title')+'</span>');
    });
    signature under construction

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17067 seconds
  • Memory Usage 2,906KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (9)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates