Home › Forums › WoodMart support forum › Change text values on page load with Jquery
Change text values on page load with Jquery
- This topic has 12 replies, 2 voices, and was last updated 6 years ago by
Artem Temos.
-
AuthorPosts
-
March 13, 2019 at 2:39 pm #112749
toulipParticipantHi 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?
March 13, 2019 at 7:51 pm #112805
Artem TemosKeymasterHi,
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
March 14, 2019 at 2:37 pm #112960
toulipParticipantHi 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?
March 14, 2019 at 2:39 pm #112961
toulipParticipantSorry, I forgot my screenshot in my previous email!
Here you are!
Attachments:
You must be logged in to view attached files.March 14, 2019 at 3:45 pm #112985
Artem TemosKeymasterYou need to use
jQuery
instead of simple$
and rework your code.March 14, 2019 at 6:01 pm #113007
toulipParticipantOk, 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!
March 15, 2019 at 6:47 am #113072
Artem TemosKeymasterYes, in the custom JS section you need to use
jQuery
.Kind Regards
April 19, 2019 at 11:12 am #119861
toulipParticipantHi 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,
April 19, 2019 at 2:21 pm #119905
Artem TemosKeymasterOur 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.
April 22, 2019 at 12:57 pm #120312
toulipParticipantHi 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
April 22, 2019 at 1:24 pm #120324
Artem TemosKeymasterThe code may work differently on different themes. There are no format requirements.
$
doesn’t work globally in WordPress andjQuery
should be used. But it is not our theme feature, it is how the WordPress works.April 22, 2019 at 1:49 pm #120330
toulipParticipantYes, 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
April 22, 2019 at 2:22 pm #120338
Artem TemosKeymasterBut you already used the code and it worked perfectly. You can take it as an example.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register