0

Below is the HTML I have to get the number from, but not sure how to pull only the number and not the last nested Span's text as well.

<li class="off" id="defense1">
    <div class="item_box defense401">
        <div class="buildingimg">
            <a title="" class="detail_button tooltip js_hideTipOnMobile slideIn" id="details401" href="javascript:void(0);" ref="401">
                <span class="ecke">
                    <span class="level">
                        <span class="textlabel">
                            Rocket Launcher
                        </span>
                        20.000
                    </span>
                </span>                   
            </a> 
        </div>
    </div> 
</li>

If I use the following VBA code, I get the text from both the Span I want and the inner span. How can I just pull out the #?

Dim IE as InternetExplorer

Set IE = new InternetExplorer
IE.document.getElementById("details401").innerText

I need VBA code that will filter just the middle Span's innerText.

Rdster
  • 1,846
  • 1
  • 16
  • 30

3 Answers3

0

Try using a this to ignore a content from a selector.

$.fn.ignore = function(sel){
  return this.clone().find(sel||">*").remove().end();
};

This is the solution that I got.

<!DOCTYPE html>
<html lang="en-US">

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            var text = $('#details401 .ecke .level').ignore("span").text();
            console.log(text);
        });
        $.fn.ignore = function (sel) {
            return this.clone().find(sel || ">*").remove().end();
        };
    </script>
</head>

<body>
    <li class="off" id="defense1">
        <div class="item_box defense401">
            <div class="buildingimg">
                <a title="" class="detail_button tooltip js_hideTipOnMobile slideIn" id="details401" href="javascript:void(0);" ref="401">
                    <span class="ecke">
                    <span class="level">
                        <span class="textlabel">
                            Rocket Launcher
                        </span> 20.000
                    </span>
                    </span>
                </a>
            </div>
        </div>
    </li>
</body>

</html>
Community
  • 1
  • 1
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

Untested:

Dim sp1, sp2

Set sp1 = IE.document.getElementById("details401").getElementsByClassName("level")(0)
Set sp2 = sp1.getElementsByClassName("textlabel")(0)

Debug.Print Trim(Replace(sp1.innerText, sp2.innerText, ""))
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
-1

You may use var numberYouWant = $(".level").text().replace($(".textlabel").text(), "").trim(); to get the number you want

ShyamK
  • 45
  • 2