copenndthagen
copenndthagen

Reputation: 50742

Inline elements like span without default styling

I am trying to add an inline element to my page. It should behave exactly like span i.e. not introduce any default styling of it's own..I want to just be able to refer this element in my JS (using id). Please help me suggest some style(less) elements like span.

Upvotes: 2

Views: 6794

Answers (2)

Anicho
Anicho

Reputation: 2667

Why not just add some extra css as mentioned by @James Allardice that removes old css and or applies new styling.

Html:

<span>My Super Cool Span</span>

<span id="MySpan>My Super Cool Span With An ID </span>

css:

span {
     width:100px;
}

span #MySpan{
     width: auto; // resetting width
     // Reset css or apply new styling
}

By doing this only spans with id MySpan will use your new styling or have their styles reset.

Look at css attributes on www.w3schools.com to find out their defaults values.

Then you can refer to MySpan in javascript by doing:

document.getElementById('MySpan')

Or in jquery by doing:

$("#MySpan")

Upvotes: 3

Tango Bravo
Tango Bravo

Reputation: 3309

Use createElement() in JavaScript

<script>
    var newElement = document.createElement('newElement');
    newElement.setAttribute('id', 'newElementId');
    var oldElement = document.getElementById('element');
    oldElement.appendChild(newElement);
</script>

<div id="element"></div>

That should add a new element type, "newElement"

Upvotes: 0

Related Questions