3

I'm using JQUERY and CSS to edit a websites default content, however I have come across the following code:

<div id="SortOptions">
    Sort by: 
    <select id="SortMain" class="improvedcatalogdropdown">
        <option value="0" selected="selected">Relevance</option>
    </select>
</div>

I need to remove the text Sort By:, but keep the select options.

I have tried this using CSS, however it removes both the text and the select options.

#SortOptions {
    display: none;
}
MMK
  • 609
  • 5
  • 16
The Codesee
  • 3,714
  • 5
  • 38
  • 78
  • Why not just delete the text "Sort by:"...? No CSS needed, really. If you hide the whole `div` you'll also hide the `select` nested into it. – some-non-descript-user Jan 17 '16 at 11:27
  • As I mentioned in the first sentence, I'm using jquery and css to override a websites default html - I have no access to that websites default code. – The Codesee Jan 17 '16 at 11:31

3 Answers3

4

See Hide text node in element, but not children You can set the visibility style to "hidden" for the element and override it for the children.

#SortOptions{
    visibility: hidden;
}
#SortOptions select{
    visibility: visible;
}

See https://jsfiddle.net/3u5zs5rj/

Community
  • 1
  • 1
Aaron J Spetner
  • 2,117
  • 1
  • 18
  • 30
1

Remove specific word using jQuery

var div = $('#SortOptions');
var newText = div.html().replace('Sort by:','');
div.html(newText)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="SortOptions">
    Sort by: 
    <select id="SortMain" class="improvedcatalogdropdown">
        <option value="0" selected="selected">Relevance</option>
    </select>
</div>
Liam
  • 6,517
  • 7
  • 25
  • 47
0

You can remove the text completely using innerHTML and replace() in Javascript.

document.getElementById('SortOptions').innerHTML = document.getElementById('SortOptions').innerHTML.replace("Sort by:","");
Rafi
  • 816
  • 9
  • 21