Until now, my approach has been deciphering and analyzing various codes and techniques for effectively utilizing jQuery, but I often find myself overwhelmed by the choices presented. This often leads to unnecessary complexity in my code.
What I aim to achieve is:
1- Verify if an id
contains a specific declaration name (the id itself).
2- Remove the controlbar
class if it does not have the suffix M4V.
3- If #postvideo
is either empty or non-existent within the parent div of articlePost
, hide .controlbar
.
4- If it ends with M4V, detach it and append it along with its attributes to the element #fold-above
... Sounds simple, right? Well, maybe not.
Here's a snippet of the code I'm working on:
$('#postvideo').not('[src$=".m4v"]').empty().each(function() {
$(".controlbar").remove(); //elements whose src doesn't end with `.m4v`
});
$('.articlePost').empty('$("#postvideo").function() {
$(".controlbar").remove();
});
$("#postvideo").detach().appendTo("#fold-above");
Multiple calls for the same id
. Can someone guide me on how to streamline all of this into concise code?