title: What jQuery function is equivalent to PHP's str_replace?
body: <p>I am trying to find all attributes of an option tag (except the value) so I can replace the option tag with a list item tag and then add the attributes to the list item.  Every Google result I come across says to use <code>replace()</code> to do this, however, I am getting the following error in console:</p>
  
  <pre><code>Uncaught TypeError: undefined is not a function
  </code></pre>
  
  <p>This occurs on the following line:</p>
  
  <pre><code>var elemAtts = $(this).replace('&lt;option value="'+$(this).prop("value")+'" ', '');
  </code></pre>
  
  <p>This is the entire script:</p>
  
  <pre><code>$('select').each(function(){
  
          var selectName = $(this).prop("name");
          var selectOpts = $(this).find("option");
          var selectPar = $(this).parent();
  
          var hiddenInput = '&lt;input type="hidden" name="'+selectName+'" value=""&gt;';
  
          var menu = '&lt;div class="jqSelect"&gt;' + 
              '&lt;div class="selected-text" id="'+selectName+'-selected"&gt;&lt;div id="'+selectName+'-text"&gt;'+$(this).find(":selected").text()+'&lt;/div&gt;' + 
              '&lt;div class="caret" onclick="$(\'ul#'+selectName+'-menu\').toggle();"&gt;&lt;/div&gt;' +
              '&lt;ul id="'+selectName+'-menu"&gt;';
  
          selectOpts.each(function(){
  
              if($(this).is(":selected")){
  
                  $('#'+selectName+'-selected').text($(this).text());
                  menu += '&lt;li class="selected"';
  
              } else {
  
                  menu += '&lt;li';
  
              }
  
              var elemAtts = $(this).replace('&lt;option value="'+$(this).prop("value")+'" ', '');
              elemAtts = elemAtts.replace('&gt;', '');
  
              menu += ' data-option-value="'+$(this).prop("value")+'" '+elemAtts+'&gt;'+$(this).text()+'&lt;/li&gt;';
  
          });
  
          menu += '&lt;/ul&gt;&lt;/div&gt;';
  
          selectPar.html(menu + hiddenInput);
  
          $('ul#'+selectName+'-menu').hide();
  
          generatedMenu = $('#'+selectName+'-menu');
          generatedMenu.find('li').each(function(){
  
              $(this).on('click', function(){
  
                  $('#'+selectName+'-text').text($(this).text());
                  $('#'+selectName+'-menu').hide();
                  $('input[name="'+selectName+'"]').attr("value", $(this).data('option-value'));
                  $(this).siblings().removeProp('class');
                  $(this).prop('class', 'selected');
              });
  
          });
  
      });
  </code></pre>
  
  <p>Basically what I am trying to do is turn this...</p>
  
  <pre><code>&lt;option value="123" rel="toggleElem" class="foo" id="bar"&gt;Hello!&lt;/option&gt;
  </code></pre>
  
  <p>Into this(string form)...</p>
  
  <pre><code>rel="toggleElem" class="foo" id="bar"
  </code></pre>