Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2013, 04:55 PM   PM User | #1
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Can a containing element affect content functionality?

Hello, everyone.

I'm not currently having an issue, but I am trying to understand something. Input is appreciated.

I am using jQuery 1.8, and in one particular document I have set up something that will delete certain files stored within a database. I can't type all the code, here, but I'll try to present an accurate facsimile.

The links to delete a particular file were anchor tags within a span, like so:
Code:
<span style="display:block;" id="span_{ unique identifier }">
  <a href="javascript:void;" name="del_{ same unique id }" id="del_{ same unique id }" class="delFile"><img for delete icon /> FILENAME.EXT</a>
</span>
Within document.ready, I had the following:
Code:
$('a.delFile').click(function(evt){
  var delID = $(this).attr('id'), spanID = delID.replace(/^del\_/,"span_");
  delID = delID.replace(/^del\_/,"");
  [[ function to delete file by ID ]]
  });
This is working fine in both IE and FF. But something has me perplexed.

I temporarily changed the span tags to paragraph tags, and while it still worked in IE, it stopped working in FF. I reverted back to span tags, and it's working just fine, again. But I'm confused as to why a <p> would prevent the delete function in FF, when <span> had no problem.

Any ideas?

Thank you,
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 01-07-2013, 05:03 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,604
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Unless you also changed $('a.delFile') to $('p.delFile') (and any occurrence of “span” to “p”, related to the element type) I see no reason why it wouldn’t work (and differently in Firefox and IE for that matter).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 01-07-2013, 05:13 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Since the functionality for deleting was for the anchor tags and not the containing span/paragraph, the $('a.delFile') was not changed to $('p.delFile').

I'm stumped. I just don't see what I'm missing.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 01-08-2013, 01:05 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Not to ask a dumb question, but...
Code:
$('a.delFile').click(function(evt){
  var delID = $(this).attr('id'), spanID = delID.replace(/^del\_/,"span_");
  delID = delID.replace(/^del\_/,"");
  [[ function to delete file by ID ]]
  })
What is the purpose of the code in red there?

And for that matter, what was the purpose in giving the <span>s an ID in the first place?

Or, turning it around the other way, why do you need *BOTH* the <span> and the <a> tags???

I'm *GUESSING* that after you delete the file you want to hide the <span> or equivalent?

Why not keep it much simpler?
Code:
<style>
.delFile {
    display: block;
    /* and any other characteristics desired */
}
</style>
...

<span id="del_{ unique identifier }" class="delFile">
    <img for delete icon /> FILENAME.EXT</a>
</span>

...
$('.delFile').click(
    function()
    {
        var delID = $(this).attr('id').replace(/^del\_/,"");

        [[ function to delete file by delID ]]

        this.style.display = "none";
    }
);
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-08-2013, 01:46 PM   PM User | #5
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
I'm using .remove() for the span, once the file is deleted. The spanID variable sets which one.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 01-08-2013, 06:05 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
So why not just do as I suggested and, instead, hide the <span>?

But even if you insist on removing it, I don't see why you need the separate <span> and <a>.

Example:
Code:
<style>
.delFile {
    display: block;
    /* and any other characteristics desired */
}
</style>
...

<span id="del_{ unique identifier }" class="delFile">
    <img for delete icon /> FILENAME.EXT
</span>

...
$('.delFile').click(
    function()
    {
        var delID = $(this).attr('id').replace(/^del\_/,"");

        [[ function to delete file by delID ]]

        this.parentNode.removeChild(this);
    }
);
The ID isn't even needed except for purposes of calling to delete the file.

But for that matter, why not forget the id and just do it by the *NAME* of the file?
Code:
<span class="delFile">
    <img for delete icon /> FILENAME.EXT
</span>

...
$('.delFile').click(
    function()
    {
        // probably better to remove the <img> node and then get just the text node
        // but this shows the general idea...just extract the filename alone:
        var fname = this.innerHTML.replace(/^\s*\<img[^\>]+\>\s*/i,"");

        [[ function to delete file by file name ]]

        this.parentNode.removeChild(this);
    }
);
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 01-08-2013 at 06:17 PM..
Old Pedant is offline   Reply With Quote
Old 01-08-2013, 08:51 PM   PM User | #7
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
But for that matter, why not forget the id and just do it by the *NAME* of the file?
If the file were stored on the server filesystem, that would be a no brainer. But they are stored in a database, with the content in one table and the file name in another table. Both tables contain the unique ID.

PS. To the mod who moved this into the Frameworks section: Although I am using jQuery, the question, itself, is not a jQuery question.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Last edited by WolfShade; 01-08-2013 at 08:54 PM..
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:46 AM.


Advertisement
Log in to turn off these ads.