Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace URL value with Jquery
    primarykey
    data
    text
    <p>I have the following HTML</p> <pre><code>&lt;div class='tile'&gt; &lt;a href='http://test-site.local' &gt; &lt;div class='tileContents'&gt; &lt;div class='tileImage'&gt; &lt;i class='icon-'&gt;&lt;/i&gt; &lt;/div&gt; &lt;div class='tileCaption'&gt; &lt;h4&gt;Logos&lt;/h4&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class='tile'&gt; &lt;a href='http://test-site.local' &gt; &lt;div class='tileContents'&gt; &lt;div class='tileImage'&gt; &lt;i class='icon-'&gt;&lt;/i&gt; &lt;/div&gt; &lt;div class='tileCaption'&gt; &lt;h4&gt;Adverts&lt;/h4&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt; </code></pre> <p>I would like to update the <code>href</code> property to any URL I wish using the values of the <code>h4</code> tags as a way to target and differentiate the two DIVs as these have the same class name.</p> <p>So for example I would like to update the URL in the a tag of the first div to:</p> <pre><code>&lt;a href="http://www.google.com"&gt; so if the value of the h4 tag = "Logos" then update the URL to "http://www.google.com" </code></pre> <p>And the same for the second DIV:</p> <pre><code>&lt;a href="http://www.yahoo.com"&gt; so if the value of the h4 tag = "Adverts" then update the URL to "http://www.yahoo.com" </code></pre> <p>I have the following but I don't think I am getting the selectors correctly:</p> <pre><code>&lt;script src="/script/jquery-1.10.2.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ var value = $('div.tile h4').html(); if (value = "Logos"); $("DIV.tile a").attr("href", "http://www.google.com"); if (value = "Adverts"); $("DIV.tile a").attr("href", "http://www.yahoo.com"); }); &lt;/script&gt; </code></pre> <p>Any help with this would be appreciated..</p>
    singulars
    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.
 

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