SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Condition and element.style...?

    Hello

    i am trying to have text-decoration applied on some text depending on the value of certain variable. If the value of myvar=0 text-deco =none and if it's 1 then text deco= line-trough...

    Kind of the same thing that emails web apps like yahoo or gmail do with mails read or unread if it's unread then email title/subject is bold/strong but if it's read then email title is in normal font-weight...

    here is some piece of code i have written to do that


    the text on which i want to apply the conditionnal decoration is a table cell (cell2DisplayCell1), the text itself is inserted by the innerHTML instruction!

    I tried to introduce the conditional statement with a function displaylinksLineThrough() which is defined in the second block code...
    Code:
    	
    
    cell2DisplayCell1.style.textDecoration = "displaylinksLineThrough(displayTitleDestbtn"+SmartLink.smartlinks_infos[sli].id_dest+", "+SmartLink.smartlinks_infos[sli].deleted+")"
    cell2DisplayCell1.innerHTML = (SmartLink.smartlinks_infos[sli].title_dest);

    Function def:


    Code:
    function displaylinksLineThrough(links_status_check, flag_deleted)
    {
    
    	if (flag_deleted == 1)
    	{
    	document.getElementById(links_status_check).style.textDecoration = 'line-through';
    	}
    
    	else
    	{
    	document.getElementById(links_status_check).style.textDecoration = 'none';
    	}
    }
    On a PHP/Java/XML/Javascript/MySQL internship right now!

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you insert text with innerHTML, you can't access it right away with getElementById(). The best thing is to build the text with document.createElement() and document.createTextNode(), save the link in a variable and then alter its text decoration.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you i will try that one...
    On a PHP/Java/XML/Javascript/MySQL internship right now!


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
  •