Jump to content

XPath everything element + nextSibling till no siblings are left?


Recommended Posts

Is it possible to retrieve a certain node + everything that comes after it in the same node? Could write some loop and start moving like that.. but from I've understood from the xpath documentation it's also possible to retrieve multiple nodes.. so I was wondering if I could get a node + all its nextSiblings.

 

This is what I have atm:

  	
var xpath = document.evaluate( '/html/body/div/div[2]/form/fieldset/h3[2]', document, null, XPathResult.ANY_TYPE, null );
alert( xpath.iterateNext() );

Which alerts the proper node, but I want everything after it as well.

 

[edit]

This has to be pretty close, but it's invalid :)

var xpath = document.evaluate( '/html/body/div/div[2]/form/fieldset/h3[2]/preceding-sibling::following-sibling::*', document, null, XPathResult.ANY_TYPE, null );

That came up blank, as did

/html/body/div/div[2]/form/fieldset/h3[2]/preceding/following-sibling::*

 

[edit]

Probably easier if I explain what I'm trying to do.

I'm trying to get everything after the second h3 in the following node:

<fieldset>
  <p><label for="post_content"></label></p>
  <h3>Post:</h3>		
  <div id="bbcode_buttons">
    <div title="bold" id="ed_bold" style="font-weight: bold;" accesskey="b" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(0);">B</div>
    <div title="italics" id="ed_italic" style="padding-right: 7px; font-style: italic;" accesskey="i" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(1);">I</div>
    <div title="underline" id="ed_under" style="text-decoration: underline;" accesskey="u" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(2);">U</div>
    <div title="strike through" id="ed_strike" style="text-decoration: line-through;" accesskey="s" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(3);">S</div>
    <div title="make a link" id="ed_link" style="text-decoration: underline;" accesskey="a" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(4);">URL</div>
    <div title="quote" id="ed_block" style="padding: 0pt 1px 1px;" accesskey="q" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(5);">“quote”</div><div title="undefined" id="ed_img" style="" accesskey="m" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(6);">IMG</div>
    <div title="ordered list" id="ed_ol" style="" accesskey="o" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(7);">OL</div><div title="list item" id="ed_li" style="" accesskey="l" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(;">LI</div>
    <div title="center" id="ed_center" style="" accesskey="c" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(9);">center</div>
    <div title="unformatted / code" id="ed_code" style="line-height: 160%; font-size: 80%; letter-spacing: 1px; font-family: anadale,serif;" accesskey="p" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(10);">CODE</div><div title="auto-close any tags you left open" id="ed_close" style="" accesskey="c" class="ed_button" onmouseover="edOver(this);" onmouseout="edOut(this);" onclick="edClick(11);">close</div></div><textarea style="clear: both;" name="post_content" cols="36" rows="8" id="post_content" tabindex="3"></textarea>

  <small>Markup: <code>BBcode a blockquote code em strong ul ol li font strike center u hr cite spoiler img</code></small><br>

  <p class="submit">
    <input id="postformsub" name="Submit" value="Add Post »" tabindex="4" type="submit">
  </p>

  <input name="_wpnonce" value="96e789d375" type="hidden"><input name="_wp_http_referer" value="/forums/topic.php?id=676" type="hidden">
  <input name="topic_id" value="676" type="hidden">
  <input name="bb_attachments" value="0" type="hidden">
  <h3>Attach files (images will be automatically inserted)</h3>
  <input type="hidden" value="33554432" name="MAX_FILE_SIZE"/>
  <span id="bb_attachments_file_sample"></span>
  <div id="bb_attachments_file_input_4"/>
  <script defer="defer" type="text/javascript"></script>
    Allowed files: gif
  <span class="num">(1000 KB)</span>
    , jpeg
  <span class="num">(1000 KB)</span>
  , jpg
  <span class="num">(1000 KB)</span>
  , pdf
  <span class="num">(1000 KB)</span>
  , png
  <span class="num">(1000 KB)</span>
  ,
  <br/>
  txt
  <span class="num">(1000 KB)</span>
  , zip
  <span class="num">(1000 KB)</span>
  , rar
  <span class="num">(1000 KB)</span>
  <br/>
  <div style="margin: 1em 0pt 0pt;"></div>
</fieldset>

 

Because I want to move all those into a new div, and attach that to where the h3 previously was.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.