Replace contents of DIV on page load with jquery

前端 未结 3 1796
再見小時候
再見小時候 2021-01-20 22:57

Using jquery is there a way I can take the contents of a DIV and replace it with something else when the page loads?

Before
相关标签:
3条回答
  • 2021-01-20 23:36

    **Replace contents of DIV on page load with jquery in worpdress 1st one replace DIV and 2nd replace just text Also Onload jQuery String Replace **

        <script type="text/javascript"> 
    
        jQuery(function($){ 
        $( ".yourclass " ).replaceWith( "<h6>New heading</h6>" );
         });
    
        </script>
     **OR For text replace**
    
        <script type="text/javascript"> 
        jQuery(function($){ 
        $( ".single_add_to_cart_button " ).text( "Sepete ekle" );
         });
        </script>
    
    
    /* For String Replace */
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript"> 
    $(document).ready(function() {
        var strNewString = $('body').html().replace(/\On hold/g,'Processing');
        $('body').html(strNewString);
    });
    
    
    EXAMPLE : 2
    
    jQuery("[lang='fr-FR']  .label-search option").each(function() {
    var text = jQuery(this).text();
    text = text.replace("All Category", "Catégories ");
    jQuery(this).text(text);
    });
    </script>
    
    0 讨论(0)
  • 2021-01-20 23:47

    Use text():

    $(".content").text("After");
    

    Live Demo: http://jsfiddle.net/heY3j/

    0 讨论(0)
  • 2021-01-20 23:51

    To piggyback off of Curt's answer the full implimentation for this would be this:

    $(document).ready( function() {
        $(".content").text("After");
    });
    

    This will execute when the window has been loaded and update the inner text of the desired div element.

    0 讨论(0)
提交回复
热议问题