Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Hide <img> with wildcard resp. with certain position inside a html code?

    Assume I have the following html code:

    <img src="/imageavatars/aaa/kk6_27-440.jpg">

    1.) I want to delete it with JavaScript. Hence the name of the image couly slightly vary from case to case I need something like a wildcard. Unfortunately the following does not work:

    $("img[src='/imageavatars/aaa/kk*.jpg']" ).css("display", "none");

    How else can I use wildcards?

    2.) Related question: Can exploit the fact that the <img> has always a position just above the closing



    If yes: How can I code therefore with JavaScript/jQuery a hide/delete instruction ?

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,012 Times in 1,009 Posts
    Something you should know before going any farther: Modern thinking has us placing the javascript after the HTML code. Thta is just before the </body> tag and not the image tag you want to hide.
    The easiest and fastest way to do this would be to give that img an ID and use the ID as the selector.
    But if you don't want to do that try
    <img src="/imageavatars/aaa/kk6_27-440.jpg">
    var ob = document.getElementsByTagName("img");
    document.getElementsByTagName("img")[ob.length-1].style.display = "none";
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts