jQuery toggleText ( Is this right way to write this method)

jQuery toggleText ( Is this right way to write this method)

$(function()
{
      $.fn.toggleText = function(data)
      {
          var oldTxt;
          var newTxt;
          if($(this).attr('toggletext') == undefined){
              oldTxt = $(this).text().trim();
              $(this).attr('toggletext',oldTxt);
              newTxt = $.trim(data);
          }else{
              newTxt = $(this).attr('toggletext').trim();
              oldTxt = $(this).text().trim();
              $(this).removeAttr('toggletext');
          }
          return (oldTxt == newTxt) ? $(this).text(oldTxt) : $(this).text(newTxt);
      }

      $('#toggleText').toggleText('New Text');
}
<div id="toggleText">Old Text</div>