I am trying to write a bit of jquery to: if there is only one instance of the div which has a class of "option" take the href attribute and redirect to that href, this is what i have to far
<script type="text/javascript">
var count =('Size: ' + $('.option').size());
if (count = 1) {
$('.readmore a').each(function () {
var url = $(this).attr('href');
window.location.replace(url);
})
}
else {
alert("more than 1");
}
</script>
It successfully redirects to the correct url, but it doesnt work properly because it if there are more than 1 instance of the div.option then it still redirects and doesnt alert "more that 1" anyone help?
im guessing at one point of the script the count is = to 1 and the jquery beings to does its redirect, but I want it to count all the instances then determine to redirect or not