1

I am trying to remove the span from the site which does not have class or id because i can not add class or id to that span because the HTML code coming through iframe

i used the below code in css

 span {display:none; }

but it hide all the span

i have the below HTML code in which i have to remove span either by css or JQuery or any other method

<div align="center" style="font-family:verdana; color:#666666; font-size:7pt; "><span class="xxxx">Content1</span> <span style="display:block; visibility:visible; position:static;">Content2</span></div>

I have to remove the Div and span those do not have class or Id

How can i do this ?

Sharma Mudeet
  • 41
  • 1
  • 4
  • You have to give us more context, there is no way of selecting a specific element without affecting others unless there is something about the element that sets it apart from the rest. Is it possible for any other divs on the page to have all those same attributes? – Kevin B Apr 26 '13 at 20:45
  • As everybody here is saying in different words - you have to find a "fixed point" in your HTML that you can trust. A wrapping element with a class or ID, or anything. Only then you can traverse to your desired, unnamed element. – DannyB Apr 26 '13 at 20:48

2 Answers2

3

To hide those elements without an id or a span, using CSS:

div, span {
    /* hides _all_ div and span elements */
    display: none;
}

div[id],
div[class] {
    /* shows those div elements that have an id or a class */
    display: block;
}

span[id],
span[class] {
    /* shows those span elements that have an id or a class */
    display: inline;
}

JS Fiddle demo.

This, though, requires the use of a browser that supports attribute-selection (which rules out Internet Explorer < 7)

With jQuery:

$('div, span').filter(function(){
    return !this.id && !this.className;
}).remove();

JS Fiddle demo.

David Thomas
  • 249,100
  • 51
  • 377
  • 410
  • May be he is referring to `div > span` with both having id and class empty. – Selvakumar Arumugam Apr 26 '13 at 20:52
  • 1
    Maybe, but until such a time as the question is edited to provide more specific instructions/requirements, I'm having to guess a little. – David Thomas Apr 26 '13 at 20:53
  • This jsless answer is nice. But since not even newer versions of IE support it, it's kinda troublesome to use. – RaphaelDDL Apr 26 '13 at 22:51
  • @RaphaelDDL: actually, and much to my surprise, [Internet Explorer 7+ supports attribute-selection, according to Quirksmode](http://quirksmode.org/css/selectors/#t20). – David Thomas Apr 26 '13 at 23:01
  • @DavidThomas Oh, that explains why Twitter Bootstrap only support IE7+, because most of their span class selectors rely on [class^=span] and so on. (Sorry couldn't search before, was on my phone's when I posted the comment :) ) – RaphaelDDL Apr 26 '13 at 23:04
  • 1
    @RaphaelDDL: as was I when I read your comment... ;) but no worries at all, you prompted me to correct the faulty assumption I'd left in my answer, which is always a good result. – David Thomas Apr 26 '13 at 23:25
1

You can try this to find element those doesn't have class attribute using Jquery.

$('span:not([class])').remove();
Sachin
  • 40,216
  • 7
  • 90
  • 102