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 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Editing string on mouse click (show/hide part)

    I am having problem with editing string on mouse click.

    I have a string of text like this:
    Code:
    id1=&id2=&id3=&id4=&amp
    And now I need to show/hide part of string by clicking on a links. I would like to hide/show each id's (i.e. id1=&amp


    It is simple to hide whole text but how about part of it ?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You would need to wrap the parts (let's say in <span>) before you can hide them

    Something like
    Code:
    <span id="id1">id1=&amp;</span><span id="id2">id2=&amp;</span><span id="id3">id3=&amp;</span><span id="id4">id4=&amp;</span>
    Then you can use code like
    Code:
    document.getElementById('id2').style.display = 'none';
    to hide a certain part

  • #3
    New Coder
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Is it possible to assign each id as var? i.e.
    Code:
    var id1 = id1=&amp;
    var id2 = id2=&amp;
    var id3 = id3=&amp;
    var id4 = id4=&amp;
    And then somehow show/hide each var ?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by meemee View Post
    Is it possible to assign each id as var? i.e.
    Code:
    var id1 = id1=&amp;
    var id2 = id2=&amp;
    var id3 = id3=&amp;
    var id4 = id4=&amp;
    And then somehow show/hide each var ?
    No, that is not possible. Do what devnull69 has suggested.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The problem is that I need to use string combined of all those id's in a link parameter so the whole link will look like:

    Code:
    src='/images/engine_components/obd.svg?id1=&amp;id2=&amp;id3=&amp;'
    so it is not ideal to have <span> tags inside

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You can still get the text only content using .innerText() ... it will automatically crop the span elements


  •  

    Posting Permissions

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