lilmer Posted March 8, 2013 Share Posted March 8, 2013 <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 More sharing options...
requinix Posted March 8, 2013 Share Posted March 8, 2013 Put the CSS into a class instead and use .toggleClass. Link to comment https://forums.phpfreaks.com/topic/275397-setting-specific-style-and-removing/#findComment-1417440 Share on other sites More sharing options...
lilmer Posted March 8, 2013 Author Share Posted March 8, 2013 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> Link to comment https://forums.phpfreaks.com/topic/275397-setting-specific-style-and-removing/#findComment-1417443 Share on other sites More sharing options...
requinix Posted March 8, 2013 Share Posted March 8, 2013 .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 https://forums.phpfreaks.com/topic/275397-setting-specific-style-and-removing/#findComment-1417455 Share on other sites More sharing options...
lilmer Posted March 8, 2013 Author Share Posted March 8, 2013 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! Link to comment https://forums.phpfreaks.com/topic/275397-setting-specific-style-and-removing/#findComment-1417472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.