Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    41
    Thanks
    14
    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">
    </body>
    </html>

    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

    </body></html>

    tags?

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

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,438
    Thanks
    23
    Thanked 630 Times in 629 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
    Code:
    <img src="/imageavatars/aaa/kk6_27-440.jpg">
    
    <script>
    var ob = document.getElementsByTagName("img");
    document.getElementsByTagName("img")[ob.length-1].style.display = "none";
    </script>
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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