Camillia
asked on
jQuery hide the first and last text in div
You can see my example here. Download and click on page.html. https://drive.google.com/file/d/1Kt2CQwvTAdY0uojPf8sf7krVu6sEz61f/view
1. When page loads, I have one row with "And" and the "X" delete.
2. I can click on Add and keep adding divs
What I want to do is:
1. The first row, remove the X
2. When on the last row ( I can have as many rows as I want)...remove And
I thought about finding the # of divs that has X and AND. If only 1, hide "X". But that's not going to work.
I think I need to drill down these divs but still not sure how to hide X and AND
1. When page loads, I have one row with "And" and the "X" delete.
2. I can click on Add and keep adding divs
What I want to do is:
1. The first row, remove the X
2. When on the last row ( I can have as many rows as I want)...remove And
I thought about finding the # of divs that has X and AND. If only 1, hide "X". But that's not going to work.
I think I need to drill down these divs but still not sure how to hide X and AND
ASKER
Ok, let me see.
I can change that but let me try the CSS first.
But note that in your template, the delete anchor and the and text you have as ids, which means you're creating multiple items with the same id every time you add a row.
I can change that but let me try the CSS first.
ASKER
Very interesting. I didn't know it can be done with CSS.
:first-of-type, :nth-child and all the ordering pseudo-elements like that can often eliminate a LOT of javascript, and make it lighter and easier to maintain.
ASKER
Doesn't work for you either...
Second row should have the "delete" (the red x delete) and "And"
Last row should have the "delete" (the red x delete)
Second row should have the "delete" (the red x delete) and "And"
Last row should have the "delete" (the red x delete)
I think that's something with the actual character / font.
Even before my changes, I still don't see red, or the character. In Chrome I see a red box, but not "X" or delete. So I think there's a font missing.
And different browsers handle missing fonts differently.
If you actually put an "X" character in the span, it will show properly.
So as soon as the font is correctly hooked up it should work.
But in your screenshot above, you also were showing "AND" on the last row, which I don't see on mine.
Even before my changes, I still don't see red, or the character. In Chrome I see a red box, but not "X" or delete. So I think there's a font missing.
And different browsers handle missing fonts differently.
If you actually put an "X" character in the span, it will show properly.
So as soon as the font is correctly hooked up it should work.
But in your screenshot above, you also were showing "AND" on the last row, which I don't see on mine.
ASKER
let me see
ASKER
Now I see it in both Chrome and Edge but why do I still see the "And" on the last row? I also see "And" when the page first loads.
I have this. I've attached my file.
page.html
I have this. I've attached my file.
#filtergroup .filterItem:first-of-type a.remCF { display:none; } /*** new*/
#filtergroup .filterItem:last-of-type #andText { font-size:0; }
<div class="col-sm-1">
<!--And-->
And
</div>
<div class="col-sm-1">
<!--delete-->
<a href="javascript:void(0);" class="remCF"><span style="color: red">X</span></a>
</div>
page.html
That's what's making me wonder about the edge version.
Edge has been "buggy" to say the least, but they update and fix pretty regularly.
I'm on V 42.17134.1.0, do you have an older one?
Edge has been "buggy" to say the least, but they update and fix pretty regularly.
I'm on V 42.17134.1.0, do you have an older one?
Ah damn, never mind.
It's because you took out the duplicate ID i mentioned. The css was specifically targeting that.
#filtergroup .filterItem:last-of-type #andText { font-size:0; }
If you can make that a class name instead, class="andText", and then change that css line to:
#filtergroup .filterItem:last-of-type .andText { font-size:0; }
Then it should work.
It's because you took out the duplicate ID i mentioned. The css was specifically targeting that.
#filtergroup .filterItem:last-of-type #andText { font-size:0; }
If you can make that a class name instead, class="andText", and then change that css line to:
#filtergroup .filterItem:last-of-type .andText { font-size:0; }
Then it should work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was it! works in both Chrome and Edge.
ASKER
I'm pretty sure you want to let the user delete the first row if you've at least two rows...
Hmmm... didn't think of that. You think I should have X on the first row as well?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So, these ?
If so, I can delete all the rows and one will remain without any And or X. Still, the first row remains. I think it's ok.
I've attached my file as well
page.html
/*#filtergroup .filterItem:first-of-type a.remCF { display:none; } */
#filtergroup .filterItem:first-of-type:last-of-type a.remCF {
display: none;
}
#filtergroup .filterItem:last-of-type .andText {
font-size: 0;
}
If so, I can delete all the rows and one will remain without any And or X. Still, the first row remains. I think it's ok.
I've attached my file as well
page.html
Yes, I think that looks and acts correctly.
ASKER
thanks for your help :)
ASKER
Interesting CSS solution. Thought this can only be done in jQuery. Thanks for your help.
If you just add the following two items it should do what you want:
Open in new window
But note that in your template, the delete anchor and the and text you have as ids, which means you're creating multiple items with the same id every time you add a row.
Since you don't have a span or anything inside the "and" area, just used font-size:0 instead of hiding it.