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