Get name of SPAN tag?

Posted on 2006-04-01
Last Modified: 2013-11-19
How can I get the name or ID of a SPAN tag on a page?  It is the only one, it is in a form, which is in a DIV, and the ID does not match the names of any of the other elements.  What we need is, but it doesnt seem to exist.  JS routine is outside form, so cannot rely on "this".
Question by:scrathcyboy
    LVL 17

    Expert Comment

    Hi scrathcyboy,

    <span name="FOO" id="BAR">

    var element = getElemenyById("BAR");
    var aForm = element.form //<-- this is what you want

    You said the ID is unique, so access the element through its id! =)

    Joe P
    LVL 7

    Accepted Solution


    Get the element ID:

    Get the element Name:
    LVL 44

    Author Comment

    BogoJoker, you miss point, we dont know name or ID of SPAN, this is what we are trying to retrieve!!
    Bubbledragon, I try yours, looks like it might work, I knew you could address the SPAN element, but did not have the right syntax.  Will let you know.  Thanks for input.
    LVL 44

    Author Comment

    Fantastic, Bubbledragon, works like a fire-breathing dragon!  For extra points can you fix an annoyance?

    When I open a popup, the URL shows in the Browser header before the Title.  Dont want this, just want the title, but cant seem to get rid of the URL infront.  When opening window, am writing this to it --

         win.document.write("<TITLE>" + divName + " Information</TITLE>");

    So it does come up with "product" Information, in browser header line, but URL is still in front of that.
    Any ideas how to get rid of the URL, it doesnt show in the main or other windows, just in the popup. (??)
    LVL 7

    Expert Comment

    I can't face your problem, I test below and the URL did't shows in the Browser header.
    Maybe get more information for testing.

         divName = "Product";
         var win ='', '', '');
         win.document.write("<TITLE>" + divName + " Information</TITLE>");
    LVL 44

    Author Comment

    No problem, am very happy to get SPAN solution, thank you lots, I will eventually figure out the browser issue, dont worry about it.  Closing off question now, Thanks and see you later.  

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now