SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    value of element by id from variable

    To get value of element by id from document is very easy:
    var example = document.getElementById('myId');

    But what if I would like to get value by id from variable:
    var example1 = '<a href="example.html" id="myId">lorem ipsum</a>'

    Is there any way?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,195
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Do you mean for instance the lorem ipsum text?

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no and I am sorry, I didn't give good example. This one is better:
    HTML Code:
    var example1 ='<div><span>sdf</span><a href="example.html" id="myId">lorem ipsum</a></div>'
    So how to get element by id from this variable to alert "<a href="example.html" id="myId">lorem ipsum</a>"

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,195
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    A regular expression would be needed to grab the id of the element, I'm not too good with them but there may be another user here that knows a pre-designed expression for this type of search.


Bookmarks

Posting Permissions

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