Jump to content

Setting specific style and removing.


lilmer

Recommended Posts

<input type='submit' class='set' id='set' value='Set'/>
<input type='text' class='mytext' id='mytext' style='font-style:italic'/>
    $('#set').click(function(){  
      
        $(cellId).css('font-weight','bold');
       
    });

 

     What I want to happen is when I click a button it make the text bold and if the text is already bold when I clicked it again it will remove the font-weight  style attribute only. Using jquery. . 

Link to comment
https://forums.phpfreaks.com/topic/275397-setting-specific-style-and-removing/
Share on other sites

Thanks, as there no other option because I need my style attributes and other attributes in there cause i'm passing all of it to a server side. 

 

<td id="D19" style="font-family:bold;font-family:Arial;font-size:11px;background-color:#FFFF00;color:#000000;" contenteditable="true">the data</td>

.toggle() is the next best thing: one function to add bold, one function to remove it.

I say this because I find it too much of a hassle to write a .click() handler that manually detects state. But you can totally do that if you'd rather: this.style.fontWeight (inside the handler) is an easy place to look.

Thank you Mr. Guru! But upon going down in the building and smoke some cigarettes, I finally got an answer just need a little conditioning and adding a attribute for each table cell. 

 

    $('#fontitalic').click(function(){        
         var cellId = $('#cellId').attr('href');         
         
         if($(cellId).attr('italic') == 'italic'){
            $(cellId).css('font-style','');
             $(cellId).removeAttr('italic');
        }else{
             $(cellId).attr('italic','italic');        
             $(cellId).css('font-style','italic');
        }
         
         
    });

 

Thanks again, you guys don't hesitate to give idea and knowledge!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.