Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts

    functions and parameters

    I need to create a function with named getFontSize()
    needs one parameter named "id"
    and id is value of object in document
    then to create a variable named object to represent object
    return font size of text in object
    use style object to retrieve font size
    and use parseInt() function to get value of font size

    this is the code i came up with

    Code:
    function getFontSize(id) {
    // Returns the font size of the object with the value id
    var object=document.getElementById(id);
    fontsize=parseInt(object.style.fontSize);
    return(fontsize);
    }
    What should i change to make work/

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    For this to work, the element under test must have its font size styled inline, not via a class.
    If that was done, how are you calling the function?

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Well using everything from external files.

    Code:
    function placeIt(id, x, y) {
    // Places the id object at the coordinates (x,y)
    object=document.getElementById(id);
    object.style.left=x+"px";
    object.style.top=y+"px";
    }
    
    
    function getFontSize(id) {
    // Returns the font size of the object with the value id
    object=document.getElementById(id);
    size=parseInt(object.style.fontSize);
    return(size);
    }
    
    function setFontSize(id, ptsize) {
    // Sets the font size of the object with the value id
    object=document.getElementById(id);
    object.style.fontSize = ptsize + "pt";
    }
    
    function changeFontSize(id, dfs) {
    // Returns the font size of the object with the value id
    fs = getFontSize(id);
    setFontSize(id, fs+dfs);
    }CSS

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Now would you care to bother to answer LogicAli's question??

    Did you read his post, at all?

    You can throw all the code at this you want, but if you used a class to set the font size, then the font size you read from the object will be null.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    understood now.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •