Search code examples
jqueryaddthis

Addthis, add the appropiate html attributes to the tags after the DOM in order to make it validate


I am trying to validate my page and I use addthis.

I load the code async and I initialize it with jQuery after the dom is ready.

function initAddThis(){
    var addthis_config = {ui_use_css : false}   
    addthis.init();
}

jQuery(document).ready(function($){      
    initAddThis();
});     

Now the validator says:

Attribute g:plusone:size not allowed on element a at this point

Here is the html part with problems:

<a class="addthis_button_google_plusone google_plusone" g:plusone:size="medium"></a>

Now, is there a way to add the appropriate attributes (g:plusone:size="medium") to the tag after the HTML is downloaded? How can I do this?

Ty


Solution

  • The first thing you need to do when working with namespaces is to set the default namespace. You do this by using the xmlns attribute on the root element of your document. In XHTML that would be the tag:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    

    http://webdesign.about.com/od/xmlnamespaces/a/xml_namespaces.htm

    The root element of the document must contain an xmlns declaration for the XHTML namespace [XMLNS]. The namespace for XHTML is defined to be http://www.w3.org/1999/xhtml. An example root element might look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title>Virtual Library</title>
      </head>
      <body>
        <a class="addthis_button_google_plusone google_plusone" g:plusone:size="medium"></a>
      </body>
    </html>
    

    http://www.w3.org/TR/xhtml1/#normative