1

So let's assume that I have a div with some value in it:

<div id="Good">
   <div id="Test4">
      <div class="hidden">
         <div class="weight">147</div>

Then let's say I wanted to use jQuery to append the whole test4 div to another div (with the same structure) called "bad" if the value was less than 100?

Right now I have my append in order but I control it with onClick:

<script type="text/javascript">
$(document).ready(function() {
 $('#Test4').click(function() {
    $('#Test4').appendTo('#bad')
 });
});
</script>

If this isn't possible could someone recommend a way to do this? Thanks!

4

2 回答 2

3

You would need to parse that value as an integer, and then test it:

$("#test4").on("click", function(){
    if ( +$(".weight", this).text() < 100 )
        $(this).appendTo("#bad");
});

Fiddle: http://jsfiddle.net/jonathansampson/fTeMH/

于 2012-06-06T17:55:48.973 回答
0

You could try something like

foo = document.getElementById("Test4")
bar = document.getElementById("bad")

bar.appendChild(foo)
于 2012-06-06T17:52:12.533 回答