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
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>
Edited by lilmer
Link to comment
Share on other sites

.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.

Link to comment
Share on other sites

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!

Edited by lilmer
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.