I have a here:
<pre class="snippet-code-js lang-js prettyprint-override">`$('#add').click(function(){
$('#list').after("<p>some text inside
some text inside
some text inside
");
});
$('#remove').click(function(){
$('.container-editor:[last][1]-child').remove();
});`</pre></p>
<pre class="snippet-code-css lang-css prettyprint-override">`.container-editor {
padding: .5em 2em 1.5em;
margin-top: 10px;
box-shadow: 1px 0 10px 1px rgba(0,0,0,0.3);
pre>
<pre class="snippet-code-html lang-html prettyprint-override">`
<p>some text inside
  some text inside
  some text inside
add remove`</pre></p>
By on the addcss a last childcss a last child CSS selector last-child vs last, a new div is to the end. By on the , the last '.-' is .
, the in the above only works once.
If I the code:
$('.container-editor:last-child').remove();
to
$('.container-editor:last').remove();
Then, the works times.
My is why does the :last-child stops after an is ? This is not in the
: for all your . Yes,I made a using after of . But stillcss a last child, to @T.J. , it is good to know that:
.-:last-child means the last child of class - in their .
:last doesn't care about , it will just the last one.
I added this new to the part about .-:last-child
<pre class="snippet-code-js lang-js prettyprint-override">`$('#remove').click(function(){
$('.container-editor:last-child').remove();
</pre>
<pre class="snippet-code-css lang-css prettyprint-override">`.container-editor {
padding: .5em 2em 1.5em;
margin-top: 10px;
box-shadow: 1px 0 10px 1px rgba(0,0,0,0.3);
pre>
<pre class="snippet-code-html lang-html prettyprint-override">`
<p>some text inside
some text inside
some text inside
some text inside
some text inside
some text inside
some text inside
some text inside
some text inside
remove`</pre></p>
The won't work in this case since there is no for all of the .- .
文章来源:https://stackoverflow.com/questions/31914671/css-selector-last-child-vs-last/31914758