Your code was almost there!
You should probably leave only the id and just add and remove the classes you need.
Also, if you really want to change the identifier, this is a text field, so you just change it using $( "#short_desc" ).attr( 'id',"full_desc"); , not $( "#short_desc" ).attr( 'id',$( "#full_desc" ) );
Finally, checking things against themselves, such as short_desc id against it id in $( '#short_desc' ).attr( 'id' ) === "short_desc" should always return true. If something always returns true, you can exclude the check. I'm going to suggest that you wanted to read more / read less instead.
Here's the working version:
$(document).ready(function () { $("#show_more").click(function () { console.log("clicked"); if ($('#short_desc').hasClass("show_desc")) { $("#short_desc").removeClass("show_desc"); $("#short_desc").addClass("hide_desc"); $("#full_desc").removeClass("hide_desc"); $("#full_desc").addClass("show_desc"); $("#show_more").text("Read Less..."); } else { $("#full_desc").removeClass("show_desc"); $("#full_desc").addClass("hide_desc"); console.log($('#short_desc').attr('id')); $("#short_desc").removeClass("hide_desc"); $("#short_desc").addClass("show_desc"); $("#show_more").text("Read More..."); } }); });
And jsfiddle to play with it.
ssnobody
source share