SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getElement problem - urgent

    Hi all!
    I'm not very good with JS but i have an urgent problem.
    I have a function to make text larger and smaller. I'm working in share point and it's not working properly. What is happening is everything in paragraph tags is getting larger but it's ignoring links within the <p> tags.

    There is nothing abnormal with the HTML, it's just <p><anchor></p>

    thanks in advance!
    here's the script

    Code:
    		function enlarge()
    	    {    
    			if (current < max)
    			{
    				current = current + 40;
    								
    				var v_p = document.getElementById('ctl00_PlaceHolderMain_Content__ControlWrapper_RichHtmlField').getElementsByTagName('p');
    				for(i = 0; i < v_p.length; i++)
    				{
    					var needsFont = true;
    					var v_p_children = v_p[i].childNodes;
    					for (j = 0; j < v_p_children.length; j++) {
    						if ((v_p_children[j].tagName) && (v_p_children[j].tagName.toUpperCase() == 'FONT')) {
    							needsFont = false;
    							break;
    						}
    					}
    					if (needsFont) {
    						// no font tag inside this paragraph, add one
    						var newFont = document.createElement('font');
    						for (j = 0; j < v_p_children.length; j++) {
    							newFont.appendChild(v_p_children[j]);
    						}
    						newFont.size = '3';
    						v_p[i].appendChild(newFont);
    					}
    				}
    				
    				var v_font = document.getElementById('ctl00_PlaceHolderMain_Content__ControlWrapper_RichHtmlField').getElementsByTagName('font');
    				for(i = 0; i < v_font.length; i++)
    				{
    					if (v_font[i].size != ''){ 
    						//alert(v_font[i].size);
    						v_font[i].size++;
    					}
    				}
    				
    				var v_div = document.getElementsByTagName('div');
    				for(i = 0; i < v_div.length; i++)
    				{
    					//alert(v_div[i].className);
    					if (v_div[i].className == 'pageTitle_Heart'){ 
    						v_div[i].style.fontSize = current + 100 + '%';
    					}
    				}
    			}	
    	    }

  2. #2
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I tested this code, the behavior is such that it is appending the font tag as a child to the paragraph. This caused it to not wrap the anchor with font but place it after the anchor.

    I would change it to work like the div code. The code for the div is setting a style on the div itself, not inserting a font tag. Can you assign a class to the p tags and then update the font size in the same way?


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
  •