5
I have two different values that must return different answers, but the classes are equal, how to solve ?
See that the answers are wrong.
.Container-Produto{display:block;border:solic 1px #ccc;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Container-Produto">
<div class="Preco">99,00</div>
<a class="Frete-a"></a>
</div>
<div Class="Container-Produto">
<div class="Preco">98,00</div>
<a class="Frete-a"></a>
</div>
<script>
jQuery("document").ready(function($){
$('.Preco').ready(function() {
var preco = $('.Preco').text();
preco = parseFloat( preco.replace( '.', '' ).replace( ',', '.' ) );
if( preco > 98.99 ) {
$('.Frete-a').text( 'Frete Grátis' );
} else {
$('.Frete-a').text( 'Sem Frete Grátis' );
}
});
});
</script>
@Bacco has an idea how to solve it here ?
– Gladson Gilberto Marinho Gonal
Just for the record, Bacco has not received notification of its above comment, Gladson. Users are only notified with
@
if they have already commented on the question or answer in question.– bfavaretto
In fact, I only saw why I came here to read. But the 2 answers contemplate the correct way to solve, and neither +1 in both ;)
– Bacco
Thanks @bfavaretto, now I understand how it works
– Gladson Gilberto Marinho Gonal
@Bacco, ask you something, in case . next() adds return in case $(this) in the subsequent tag to ". Price", but if there are any other tags between them, how do I solve ?
– Gladson Gilberto Marinho Gonal
I think it’s fundamental that you understand the selectors from jQuery, as they are the basis of what you will do. In Portuguese, I found a video here in a quick search, I don’t know if it’s good because I just watched the beginning, but try to see if you can solve it: http://vimeo.com/15991889
– Bacco
And for you to know, the next of the form that was put in the accepted answer is returning the "next . Shipping-a" and not the next tag any.
– Bacco
I tried to see all selectors today, I tested several, but I did not find one that selected the tag I want that appears the text "Free Shipping", I will see the video, thank you very much
– Gladson Gilberto Marinho Gonal
@Bacco, why . find() does not work in this case, she should not find the TAG with the class I wanted ?
– Gladson Gilberto Marinho Gonal
.find is to find a tag inside another tag. If you’re outside, you may need other selectors. Better to give a good effort in the study of the selectors and do more tests (cut the desired code and test it separately in a SQL Fiddle, for example), because you will always be bumping into this type of problem.
– Bacco
I’ve been in Dreamweaver here since early, not being able to even select where I want to perform the function,...
– Gladson Gilberto Marinho Gonal