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);
Member Avatar for LastMitch

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.