Tricky CSS selector

Discussion in 'CSS' started by Smellypunks, Sep 7, 2010.

  1. #1
    I am trying to target an element <a title="next"> which is generated by the server without any class or id tag. I have tried the [title] atribute selector but this selects a number of objects on the page and I only want to select this one. I tryed targeting it like this:-

    body div a[title]
    Code (markup):
    But again this picks up a number of simlar objects on the page. How would I select the <a title="next"> object?

    snippet from page

    <page>
    <div>
    <a title="Next" href="/wapprivate/wapLocationSetSearch.do?move=Next">Next</a>
    <div>
    <div id="quickNav">
    <div class="controls">
    //lots more code with using the <a title="xxxxx"> tag
    HTML:
     
    Smellypunks, Sep 7, 2010 IP
  2. Piotr Aszoff

    Piotr Aszoff Active Member

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    53
    #2
    if you want to select just one link (A tag), you can use jquery:
    $(document).ready(
    	function()
    	{
    		$("a:eq(0)").css("border", "1px solid black");
    
    })
    Code (markup):
    It selects the first A element in the body section of your html file and sets the style for it.
    Hope it helps, Peter
     
    Last edited: Sep 7, 2010
    Piotr Aszoff, Sep 7, 2010 IP
  3. Piotr Aszoff

    Piotr Aszoff Active Member

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    53
    #3
    but if you want to select all links titled by Next use:

    $("a[title]=Next").css("border", "1px solid black");
     
    Piotr Aszoff, Sep 7, 2010 IP
  4. cubicaaron

    cubicaaron Guest

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Piotr has hit the nail on the head - the only way you can do this in a robust manner that is compatible throughout browsers is through JQuery.
     
    cubicaaron, Sep 8, 2010 IP
  5. FilmFiddler

    FilmFiddler Greenhorn

    Messages:
    54
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    23
    #5
    Perhaps you've tried this already, but extending your original example to include the targetted title value of "Next" ...

    body div a[title="Next"]
    Code (markup):
    Note that Attribute Selectors don't work in IE6 or earlier.
     
    FilmFiddler, Sep 8, 2010 IP
  6. siothach

    siothach Active Member

    Messages:
    656
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #6
    try to style tags by title attribute look like bad idea, have you have a lot of title need to be styled? so create hundreds of wasting css code lines?

    why dont try class attribute? or css DOM?
     
    siothach, Sep 8, 2010 IP
  7. cubicaaron

    cubicaaron Guest

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    siothach is correct - its a really bad way of doing this. Is there no way you can edit the output to put ID's or CLASS attributes on the DIV's?

    How are the pages produced, Via a CMS?
     
    cubicaaron, Sep 8, 2010 IP
  8. Smellypunks

    Smellypunks Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks for all the feedback. To answer the question no there is no way of getting the server to push the code with class or ID. I dont really want to have to use JS or Jquery. It is just the one title tag I am trying to effect not lots of different ones. So for me the solution was

    body div a[title="Next"]
    Code (markup):
    cheers

    :cool:
     
    Smellypunks, Sep 8, 2010 IP