Igor O Igor O - 10 months ago 49
CSS Question

Issue trying to move a label using insertAfter on Safari

For some specific condition, I want to move a label element to the top. My solution was very simple:



$("label[for='option_3']").insertAfter("label[for='option_0");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<label for="option_0">
first item
</label>
<label for="option_1">
second item
</label>
<label for="option_2">
third item
</label>
<label for="option_3">
forth item
</label>
<label for="option_4">
fifth item
</label>





It worked pretty well on Firefox and Chrome, but it didn't work on Safari (Version 10.0.1 (12602.2.14.0.7)).

Any idea?

Answer Source

There is an issue with you jQuery statement it should be

$("label[for='option_3']").insertAfter("label[for='option_0']");

you are missing to close the '' and [] after option_0. Chrome is intelligent enough to handle this issue by itself but safari is not

$("label[for='option_3']").insertAfter("label[for='option_0']");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<label for="option_0" id="one">
  first item
</label>
<label for="option_1">
  second item
</label>
<label for="option_2">
  third item
</label>
<label for="option_3">
  forth item
</label>
<label for="option_4">
  fifth item
</label>