CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: removing img tag  (Read 95 times)

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
removing img tag
« on: 23 Aug 2023, 12:52:05 am »
Hi,

i need to remove an image tag.  I managed to add it creating the element when i type the name and then blur the field.  But when i remove the name and blur the field it should remove the image, if not then i get up with two images the next time...

js

Code: [Select]
  if(!name)
   {
     var rem = document.getElementById('useravatar');
     
     if(rem)
     {
         
       rem.removeChild;  //does not work
       
       return true;
         
     }
     
     return false;
   }


here is how it was created

Code: [Select]
               ht = "32";
               wd = 32;
               
               var newtag = document.createElement('img');
                   newtag.setAttribute('id', "usr_avatar");
                   newtag.setAttribute('src', data);
                   newtag.setAttribute('alt', "user avatar display");
                   newtag.setAttribute('height', ht);
                   newtag.setAttribute('width', wd);             
                   
                   sa.appendChild(newtag);



html before the image is created
Code: [Select]
     <li>
       <label for="user_blocklist">Block User</label>
       <br>
       <input type="text" name="user_blocklist" id="user_blocklist" min="5" max="25" size="25" placeholder="Enter Username To Block"  onBlur="grabUserAvatar(this.value, 'ajax_user_icon.php', 'useravatar');">

               <span id="useravatar"></span>
    </li>



source after the image is created

Code: [Select]
<span id="useravatar">
<img id="usr_avatar" src="https://example.com/user_images/testermike/padlock_1692761384_1_thumb.png" alt="user avatar display" height="32" width="32">
</span>

and the image

https://photos.app.goo.gl/Bvu8vqzDBu7L5LAx8



how do i remove it when i remove the name from the field and then leave the field ?

Thanks

Update:   got it

Code: [Select]
if(!name)
   {
     var rem = document.getElementById('useravatar');
     
     if(rem)
     {
         
        rem.remove();
       
       return true;
         
     }
     
     return false;
   }
   

« Last Edit: 23 Aug 2023, 04:49:43 am by durangod »

 

SMF spam blocked by CleanTalk

Advertisement