Home Forums WoodMart support forum Change text values on page load with Jquery

Change text values on page load with Jquery

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #112749

    toulip
    Participant

    Hi guys,

    I have written a function in Javascript + Jquery with which I try to change the text on my webpages after they are loaded.

    This is the code:

    Html:

    <div class="welcome">
    			
      <p>
            Welcome.<br>
            I like pie.<br>
    	Do you like pie?
      </p>
    
    </div>

    Javascript + Jquery:

    changeText = function(text, newText){
    var currentText = $('.welcome').html();  
        
    $('.welcome').html(currentText.replace(text,newText));
    		
    };
        
    window.setTimeout(function(){changeText('Welcome.', '<b>How are you?</b>')});

    So, I am sending you this message because this code does not work on your theme and after I place it in the Global JS section. For the records, it works fine on another website that I am running for testing such features.

    Please, do you know if I have to place it anywhere else in your theme settings?

    #112805

    Artem Temos
    Keymaster

    Hi,

    Please, send us a link to the page where you have this code placed so we can see why it doesn’t appear on your website.

    Regards

    #112960

    toulip
    Participant

    Hi guys,

    Well, here I am sending you the example Url: https://hatziligos.com.gr/%CE%B7%CE%BB%CE%B5%CE%BA%CF%84%CF%81%CE%B9%CE%BA%CE%AC-%CE%B1%CE%BD%CF%84%CE%B1%CE%BB%CE%BB%CE%B1%CE%BA%CF%84%CE%B9%CE%BA%CE%AC-%CE%B1%CF%85%CF%84%CE%BF%CE%BA%CE%B9%CE%BD%CE%AE%CF%84%CF%89%CE%BD/%CE%B3%CF%81%CE%B1%CE%BD%CE%B1%CE%B6%CE%B9%CE%BC%CE%B9%CE%B6%CE%B1%CF%830/c%CE%B1r-%CE%B3%CF%81%CE%B1%CE%BD%CE%B1%CE%B6%CE%B9-%CF%84-v%CE%B1l%CE%B5%CE%BF-17/

    I am also attaching you a screenshot of the text that I would like to change! For the records, the above URL is about a single product page. So, let’s say that I would like to change the text in the red frame as concerns the screenshot that I have just attached to you.

    I use the following code in your theme settings -> global js, but it does not work.

    changeText = function(text, newText){
    var currentText = $('.wc-tab-inner ').html();  
        
    $('.wc-tab-inner ').html(currentText.replace(text,newText));
    		
    };
        
    window.setTimeout(function(){changeText('Splines', '<b>Σπλίνες</b>')});

    Could you please assist me?

    #112961

    toulip
    Participant

    Sorry, I forgot my screenshot in my previous email!

    Here you are!

    Attachments:
    You must be logged in to view attached files.
    #112985

    Artem Temos
    Keymaster

    You need to use jQuery instead of simple $ and rework your code.

    #113007

    toulip
    Participant

    Ok, I see.

    That worked perfectly for me now! So, this is the case everytime that I would like to write some jquery code! I will have to write jquery instead of $, right?

    Thanks once again for your really valuable help!

    #113072

    Artem Temos
    Keymaster

    Yes, in the custom JS section you need to use jQuery.

    Kind Regards

    #119861

    toulip
    Participant

    Hi there,

    I need some help regarding jquery codes.

    I have this code:

    jQuery(function($) {
    
    $("img").hover(function () {
    		 
      
     $(this).data("title",$(this).attr("title")).removeAttr("title");
    		  }, 
    		  function () {
    			$(this).attr("title",$(this).data("title"));
    		  }
      
    		);
    });

    I use this in order to remove images’ titles on hover.

    So, how should I write this code in the custom JS field in settings in order to properly run it?

    Thanks,

    George,

    #119905

    Artem Temos
    Keymaster

    Our fields don’t have any requirements for the JS code. We are not able to test third-party codes since it is hard to understand how they should work and it is out of our theme support scope.

    #120312

    toulip
    Participant

    Hi again,

    Thanks for your support!

    For the records, I do use the above code in another WordPress website and works perfectly for me. I do not want you to check my code but to tell me the format that I should use in the custom JS code settings.

    I know that I will have to use jquery instead of $. Well, I did so, but nothing happened on my front end.

    Thanks,

    George

    #120324

    Artem Temos
    Keymaster

    The code may work differently on different themes. There are no format requirements. $ doesn’t work globally in WordPress and jQuery should be used. But it is not our theme feature, it is how the WordPress works.

    #120330

    toulip
    Participant

    Yes, of course.

    Ok then, I will try to see how this should be written in your theme.

    By the way, could you send me a simple example function in JS code just showing me the main format that I will have to follow? Or are there any links available into your documentation files?

    Thanks,

    George

    #120338

    Artem Temos
    Keymaster

    But you already used the code and it worked perfectly. You can take it as an example.

Viewing 13 posts - 1 through 13 (of 13 total)