views:

32

answers:

3

What I'm trying to do is search a page for an element that has the string 'tab_selected' in the class name. The class name is more than just 'tab_selected'. Its 'tab_selected + the UUID'. The UUID changes so all I really want to search for is if the class name contains 'tab_selected' and then if it does I want to get the ID of that element and set the cookie with that ID. I'm a terrible Noob with javascript so any direction would be awesome. Thanks!

A: 

EDIT:

Thats actually fairly simple with jQ:

var sel = '.tab_selected_left_horizontal, .tab_selected_right_horizontal, .tab_selected_text_horizontal, .tab_selected_left_vertical, .tab_selected_text_vertical, .tab_selected_right_vertical';

var ids = $(sel).map(function(){
  return $(this).attr('id');
});

I would recommend adding an additional class of tab_selected without the UUID. This way you can grab all the elements of that class without having to parse class names. So you element might look like this:

<div class="tab_selected tab_selected-UUID"></div>

This way you can just do $('.tab_selected').

prodigitalson
ooops Nick was right. the UUID is not in the class. I've missread my own code. That should make it easier then I think...It could have one of a bunch of different classes. Either tab_selected_left_horizontal, tab_selected_right_horizontal, tab_selected_text_horizontal, tab_selected_left_vertical, tab_selected_text_vertical, or tab_selected_right_vertical. So what I could say is if its any one of those classes then get the id...correct? Ok so the harder part is actually writing that code...
Richard
see my edit... if youre using jquery it should be easy-peasy... if youre using raw js, itll be a little more involved.
prodigitalson
A: 

Just a guess, but if you're trying to save a cookie from your selected tab jquery can do it for your:

You will need, jquery-ui and a cookie plugin for it, then all you have to do is change your tabs initialization:

<script type="text/javascript">
  $(function() {
    $("#tabs").tabs({
      cookie: {
        // store cookie for a day, without, it would be a session cookie
        expires: 1
      }
    });
  });
</script>

Cookie plugin is here

madeinstefano
The tabs are generated through coldfusion and I'm not sure how what is currently written in coldfusion could work with jquery-ui. I'm just trying to take what is currently output and work with that. Thanks for the suggestions!
Richard
A: 

Ok it was much more simple than I was making it. Thanks everyone for your help! Here was my test and it worked perfectly.

$(document).ready(function() { $(".tab_selected_text_horizontal").attr("id"); var title = $(".tab_selected_text_horizontal").attr("id"); alert(title); });

Richard