Reputation: 24132
Summary
I have to delete blank entries before they get submitted to the server.
The elements to be selected are HTML tables with an Id. They have all the same Id pattern.
Id Pattern: couvertureAdditionnelle_%
%: it's a given index based on the number of tables with such an Id on the page.
So for instance:
<table id="couvertureAdditionnelle_0">
...
<table id="couvertureAdditionnelle_0_descriptions">
...
</table>
...
</table>
<table id="couvertureAdditionnelle_1">
...
<table id="couvertureAdditionnelle_1_descriptions">
...
</table>
...
</table>
...
<table id="couvertureAdditionnelle_13">
...
<table id="couvertureAdditionnelle_13_descriptions">
...
</table>
...
</table>
...
So, I already have a javascript function to delete a single row for which the given table id is assigned directly whilst it's generated by the server.
I now want to get these tables and check on the client whether they are empty. If they are, then I need to delete them so that they don't get submitted to the server.
Current situation
As of now, I am almost there, only missing a little touch to get it working.
var couverturesAdditionnelles = $("table[id^=couvertureAdditionnelle_");
I got all the tables I want, plus those I don't. Yes, because I also get tables named like couvertureAdditionnelle_0_descriptions
.
Question
Basically, I want to select only the tables named like:
`couvertureAdditionnelle_0`
How can I select only those?
Or how can I avoid to select the tables named like couvertureAdditionnelle_0_descriptions
?
Upvotes: 0
Views: 180
Reputation: 65796
You can exclude certain members from the found elements with the :not()
pseudo-class:
var couverturesAdditionnelles =
$("table[id^=couvertureAdditionnelle_]:not([id$=_descriptions]"));
Upvotes: 2