2

I have this HTML code from Sharepoint and I was wondering if it's possible to delete this specific DOM element based only on the "text" attribute?

<ie:menuitem menugroupid="200" text="new docs view" onmenuclick="window.location = '/some link/';" type="option" id="zz36_View1"></ie:menuitem>

Using Firebug I can simply right click the above line and click delete element. How do I do this using Javascript w/ Jquery?

Here's some context of where the above line came from:

<span style="display:none">
    <menu compactmode="true" id="zz34_ViewSelectorMenu" type="ServerMenu">
        <ie:menuitem menugroupid="100" text="All Documents" onmenuclick="window.location = '/some link/';" type="option" id="zz35_DefaultView"></ie:menuitem>
        <ie:menuitem menugroupid="200" text="new docs view" onmenuclick="window.location = '/some link/';" type="option" id="zz36_View1"></ie:menuitem>
        <ie:menuitem menugroupid="300" text="Explorer View" onmenuclick="window.location = '/some link/';" type="option" id="zz37_View2"></ie:menuitem>
    </menu>
</span>

I tried something like:

<script language="Javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>

<script language="Javascript">
    $(document).ready(function() {
        $('ie:menuitem[text*="new docs view"]').remove();
    });
</script>

but it doesn't really work.

5 Answers 5

4

Try

$('ie\\:menuitem[text*="new docs view"]').remove();
//or
$('menuitem[text*="new docs view"]').remove();

Just a guess since I really don't know how well jQuery works with namespaces.

Sign up to request clarification or add additional context in comments.

Comments

0
$('ie:menuitem[text*="new docs view"]')

ie:menuitem is not a standard HTML element. Therefore jQuery is likely interpreting :menuitem as a selector. That's likely the root of your problem.

Comments

0

$('ie\\:menuitem[text*="new docs view"]').remove() may work.

Comments

0

That's how you can do. Assuming your menu is the first children: (dirty way)

$("span").children(1).children().each(function(){
    if($(this).attr("text") == "new docs view"){
        $(this).remove();
        return;
    }
});

Jsfiddle: http://jsfiddle.net/naveed_ahmad/wdTwL/

Comments

0

You have to escape the : in your selector:

$("ie\\:menuitem[type='option'][text='All Documents']").remove();

Shown working here: http://jsfiddle.net/Codemonkey/tduVq/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.