<span class="here one-two-sdfs test">click1</span> <br />
<span class="here one-two-3er te3st">click2</span> <br />
<span class="here one-two-sdwrer test">click3</span> <br />
<span class="here one-two-s-ere test">click4</span> <br />
<span class="here one-two-wer-r test">click5</span> <br />
<span class="here one-two test">click6</span> <br />
$('.here').click(function(){
var one-two = ????
alert(one-two);
})
fiddle
i would like -
if i click on click1 then alert show me one-two-sdfs
if i click on click2 then alert show me one-two-3er
if i click on click3 then alert show me one-two-sdwrer
if i click on click4 then alert show me one-two-s-ere
if i click on click5 then alert show me one-two-wer-r
if i click on click6 then alert show me one-two
i would like show class with begin one-two- how can i make it?:)
<span class="here one-two-sdfs test">click1</span> <br />
<span class="here one-two-3er te3st">click2</span> <br />
<span class="here one-two-sdwrer test">click3</span> <br />
<span class="here one-two-s-ere test">click4</span> <br />
<span class="here one-two-wer-r test">click5</span> <br />
<span class="here one-two test">click6</span> <br />
$('.here').click(function(){
var one-two = ????
alert(one-two);
})
fiddle
i would like -
if i click on click1 then alert show me one-two-sdfs
if i click on click2 then alert show me one-two-3er
if i click on click3 then alert show me one-two-sdwrer
if i click on click4 then alert show me one-two-s-ere
if i click on click5 then alert show me one-two-wer-r
if i click on click6 then alert show me one-two
i would like show class with begin one-two- how can i make it?:)
Share Improve this question edited Jul 25, 2012 at 9:38 Luck Mendizo asked Jul 25, 2012 at 9:32 Luck MendizoLuck Mendizo 211 silver badge4 bronze badges 1- 2 Did you try doing any reading on regular expressions and work yourself? – T.J. Crowder Commented Jul 25, 2012 at 9:39
3 Answers
Reset to default 4http://jsfiddle/tMzAH/10/
$('.here').click(function(){
var onetwo = this.className.match(/\bone-two[^\s]*/);
console.log(onetwo[0]);
})
This should work.
$('.here').click(function(){
var one_two = $(this).attr("class").match(/\bone-two\S*/)[0];
alert(one_two);
})
Get the className of the element you clicked. And then split it. You do not need RegEx for this ;)