Note that there are some explanatory texts on larger screens.

plurals
  1. POHide element in HTML generated by JSP file until additional script is loaded
    primarykey
    data
    text
    <p>I want to use Google Content Experiments to test different versions of a search bar. The search bar on this site (<a href="http://cookware.lecreuset.com" rel="nofollow noreferrer">see here</a>) is part of a JSP file that I am not able to manipulate outside of a complicated and time-consuming process; it is also tied to a CSS file on the server that I can't update.</p> <p>What I can do is use our CMS to add CSS and jQuery, but with the code I have written below, the original search bar still shows for a flash before <strong>visibility: none</strong> hides it, and then the new version displays. </p> <pre><code> &lt;style type="text/css"&gt; #search-box, #search-box form#CatalogSearchForm{visibility: hidden;} &lt;/style&gt; &lt;script src="https://www.google-analytics.com/cx/api.js?experiment=PNsL-7hLRy-zjV_zTZrBLQ"&gt;&lt;/script&gt; &lt;script&gt; var chosenVariation = cxApi.chooseVariation(); &lt;/script&gt; &lt;script&gt; var pageVariations = [ function() {$('#search-box, #search-box form#CatalogSearchForm').css('visibility','visible'); console.log('original');}, function() { $('#search-box button').css({ color: '#fff', 'background-image': 'url(/wcsstore/CVWEB/images/home/search-bar-btn.png)', height: '22px', width: '22px', position: 'absolute', right: '0px' }); $('#search-box').css({ background: 'none', border: '1px solid #000', position: 'relative', width: '190px' }); $('input#searchTerm').css({ 'font-weight': 'bold', 'text-transform': 'uppercase', 'font-size': '11px', }); $('#search-box, #search-box form#CatalogSearchForm').css('visibility','visible'); $('input#searchTerm').val('SEARCH'); $('#search-btn').empty(); console.log('Test1'); }, function() { $('#search-box').css({ 'background-image': 'url(/wcsstore/CVWEB/images/home/search-bg-neutral.png)', }); $('#search-box button#search-btn').css('color', '#fff'); $('#search-box, #search-box form#CatalogSearchForm').css('visibility','visible'); $('input#searchTerm').val('Search'); console.log('Test2'); }, ]; $(document).ready( pageVariations[chosenVariation] ); &lt;/script&gt; </code></pre> <p>Is there another front-end method I can use to hide the search bar until my script is loaded and the correct version of the search bar can display? Most of the posts I've seen here suggest adding display: none to the actual element via inline CSS but that isn't an option in this case. I did find <a href="https://stackoverflow.com/questions/1855998/jquery-how-to-hide-divs-they-are-showing-for-a-split-second-on-page-load?rq=1">this post</a> which brings up a good point about users w/out JS enabled but I will worry about that if I can get the search bar to hide on load.</p> <p>If you look at that same page, you'll see the "L'Atelier" in the navigation - that text is manipulated successfully with CSS/jQuery, and the incorrect text does not flash before the corrected text is loaded. The technique is the same - does the search bar show first because it's a bigger element (more than just text and URL)? This is the code for that piece, which works perfectly</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("ul#links &gt; li:contains('PARTNERS')").addClass("brand-content"); var brandContent = $('ul#links &gt; li.brand-content &gt; a').text(); if (brandContent == 'PARTNERS'){ $('ul#links &gt; li.brand-content &gt; a').text("L’Atelier").attr("href", "/cookware/content_latelier_10151_-1_20002").attr("onClick", "_gaq.push(['_trackEvent','TopLevelNav', 'Click', 'Latelier']);"); } $('ul#links').show(); &lt;/script&gt; &lt;style type="text/css"&gt; ul#links { display: none; } &lt;/style&gt; </code></pre> <p>The site runs jquery 1.3.2, which can't be updated at this time. I am open to all ideas and suggestions on how to achieve this that would be compatible w/ that version of jQuery.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload