SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem applying DIV Justify (JavaScript DOM)

    I am having problem applying the DIV Justify on the line mentioned below. 'theLink' is formatted URL and the rest is normal text. So, I am getting 'Type Mismatch' error. But, I want to apply the <DIV align='Justify'> for the total. Any ideas please ?

    function createTable()
    {
    var x = xmlDoc.getElementsByTagName('topic');
    var newEl = document.createElement('TABLE');
    var tmp = document.createElement('TBODY');
    newEl.appendChild(tmp);
    var row = document.createElement('TR');
    var container = document.createElement('TD');
    var pos = Math.floor(Math.random() * x.length);
    var topicTitle = document.createTextNode(x[pos].childNodes[0].firstChild.nodeValue);
    var topicUrl = document.createTextNode(x[pos].childNodes[1].firstChild.nodeValue);
    var topicContent = document.createTextNode(x[pos].childNodes[2].firstChild.nodeValue);
    var theDiv = document.createElement('DIV');
    theDiv.setAttribute('align','justify');
    var theLink = document.createElement('A');
    theLink.setAttribute('href', topicUrl.data);
    theLink.setAttribute('title', topicTitle.data);
    theLink.appendChild(document.createTextNode(topicTitle.data));
    var myHtml = document.createTextNode(': ');
    theDiv.appendChild(theLink+document.createTextNode(': '+topicContent.data)); ---------- ERROR ON THIS LINE ---------
    container.appendChild(theDiv);
    row.appendChild(container);
    tmp.appendChild(row);
    document.getElementById('spotlight').appendChild(newEl);
    }
    </script>

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use theDiv.style.textAlign='justify',
    or set it in a css class and give these div's a className.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. The problem is applying the DIV for the whole content.

    The problem is with the following line.
    theDiv.appendChild(theLink+document.createTextNode(': '+topicContent.data));

    If I have the following line without 'theLink', DIV works fine.
    theDiv.appendChild(document.createTextNode(': '+topicContent.data));

    But, I want to apply 'theDiv' for 'theLink' and appended text together.

    Any other ideas please.

    Thanks.


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
  •