How can I change the order of words in an element?

The timeout function can possibly be omitted, but was necessary in my case. $(document).ready(function() { setTimeout(function() { var text = $(‘.slp_result_citystatezip’).html().split(‘ ‘); $(‘.slp_result_citystatezip’).text(text[1] + ‘ ‘ + text[0]); }, 1000); });

How to fix the "Uncaught TypeError: a.indexOf is not a function" error?

The error message often occurs when outdated commands are used that are no longer supported in current jQuery versions. Solution: If possible, reprogram the code so that it is up to date. Otherwise, the jQuery Migrate plugin, which allows the use of older code, can help. <script src=”https://code.jquery.com/jquery-3.3.1.min.js”></script> <script src=”https://code.jquery.com/jquery-migrate-1.4.1.min.js”></script>

How can I display a hint only on subpages with a special URL?

The following code inserts a hint on all subpages of a domain if a certain string is present within the URL. function add_code_to_body() { if (strpos($_SERVER[‘REQUEST_URI’], ‘zeichenfolge-in-der-url’) !== false){ ?> <div style=”background-color:#000;color:#fff;font-size: 17px;padding: 8px;text-align: center;”>Here comes the hint.</div> <?php } } add_action( ‘wp_body_open’, ‘add_code_to_body’ );

How can I add or remove a CSS class with a click?

<ul id=”navlist”> <li id=”home”><a class=”nav” href=”home”>Home</a></li> <li id=”about”><a class=”nav” href=”about-us”>About Us</a></li> </ul> $(‘#navlist a’).click(function(e) { e.preventDefault(); $(‘#navlist a’).removeClass(‘selected’); $(this).addClass(‘selected’); });

How can I display a div element only when a specific element is in view?

If you want a certain element to be visible only when another element appears during scrolling, the following code can be helpful. var p = $( “.passedMe” ); //Element that appears var offset = p.offset(); offset = offset.top; $(window).scroll(function () { if ($(window).scrollTop() > offset ) { $(‘.showHide’).fadeIn(); //Element that should become visible } else […]

How can I play a CSS animation only when it appears in the viewpoint?

The following example makes a CSS animation run only when it is in the user’s field of view, which is achieved, for example, by scrolling. Thereby an image becomes visible, which results in a drawn line. The drawn line already exists as an image. By CSS this is completely hidden at the beginning and then […]

How can I change other button name after a button click?

The default is relatively simple, after clicking on a button, a new element is displayed, which also contains a button. This button is different from the function, but has the same name as the first button and therefore causes irritation. The following script solves exactly this problem. <script type=”text/javascript”> jQuery( document ).on( ‘click’, ‘.KlasseDesErstenButtons’, function( […]

How can I display more content and change the name of a more button?

The problem is quite simple. We have too much text on a page and want to hide some of this text and only show it when needed. This function should happen via a button. This is labeled “More” and should change to “Less” when the rest of the text is faded in. Solution: The following […]