SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast tenfingers's Avatar
    Join Date
    May 2004
    Location
    Alberta, Canada
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Well-formedness in image creation method

    How does one generate a well-formed xhtml compliant image tag using the createElement method?
    Here is the case I'm working on, which creates an image element with document referrer in the query string
    Code:
    var doRefer = function() {
    var d = document, r = d.referrer;
    if (d.getElementById("axs")) {
    	var obj = d.getElementById("axs");
    	var img = document.createElement('img');
    	obj.appendChild(img);
    	img.src = '/cgi-bin/axs/****.pl?trans.gif&ref=' + r;
    	img.width = 1;
    	img.height = 1;
    	img.title = 'AXS';
    	};
    };
    This is triggered with addEvent(); by Dean Edwards, et al.

    The image tag created is HTML 4, not XHTML. While it serves its specific purpose in this instance, with no affect on what the user experiences, it would be nice to know how to create a well-formed tag for use within the document.
    Cheers!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    With XHTML you use createElementNS() instead of createElement() as XHTML also requires that the appropriate namespace be specified. You can't use HTML JavaScript DOM commands with XHTML, you need to use the XHTML JavaScript DOM commands for that. Of course the will only work if your page is actually being served as XHTML and not just as malformed HTML.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast tenfingers's Avatar
    Join Date
    May 2004
    Location
    Alberta, Canada
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by felgall View Post
    ...Of course the will only work if your page is actually being served as XHTML and not just as malformed HTML.
    So if we're serving text/html from a shared hosting server then there's little or no point in using XHTML Javascript DOM commands, even if the DOCTYPE is set to XTHML 1.0 Strict?

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tenfingers View Post
    So if we're serving text/html from a shared hosting server then there's little or no point in using XHTML Javascript DOM commands, even if the DOCTYPE is set to XTHML 1.0 Strict?
    If you're serving as text/html, then you are using HTML, no matter what the DOCTYPE declaration is.
    Birnam wood is come to Dunsinane


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
  •