0

Quick question. I want to make a variable from just a section(substring?) of an id in javascript / or jquery. I've got four possible id names: link_north, link_south, link_east, link_west.

I want to pull just the direction from the link to use as a variable, with this:
var header_change = $('.link_selected').attr('id');

How can I get rid of the 'link_' part?

I know it might be easier to just change the id names, but that's not what is wanted.

I got this far, but I don't know how to get just the second item?

var header_change = $(".link_selected").attr("id");
                    var n=header_change.split("_");
                    alert(n);

Edited by turpentyne

2
Contributors
1
Reply
10
Views
4 Years
Discussion Span
Last Post by LastMitch
0

I know it might be easier to just change the id names, but that's not what is wanted.

How did you change it?

This might be the way I can think of:

var header_change = $(".link_selected").attr('id');
var id = $(this).find('link_').text();
$('<div class="items" id="link_'+id+'"></div>');

Not really sure it will work because there is other id numbers involves.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.