Through this:
var all = $("#innerhtml").map(function() {
return this.innerHTML;
}).get();
alert(all);
I find:
<a class="cart-btn remove text-muted small" onclick="removeCart('fgh', 'ser');"><i class="fa fa-minus-circle"></i></a>
<a class="name-image" >
<span class="name">
<span class="quantity">28 × </span>rum ‘n’ beat</span>
</a>
<p class="comment-amount">
<span class="amount pull-right">kr3,584.00</span>
</p>
How can i get this in to a jQuery variable..
You can use Jquery attr().
var result = $('.cart-btn').attr("onclick")
console.log(result);
var re = /'(.*?)'/g;
var [a,b,c] = result.match(re);
console.log(a, b, c);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="cart-btn remove text-muted small" onclick="removeCart('89', '7647966b7343c29048673252e490f736', '0');"><i class="fa fa-minus-circle"></i></a>
<a class="name-image" onclick="openMenuOptions('89', '7647966b7343c29048673252e490f736');">
<span class="name">
<span class="quantity">28 × </span>rum ‘n’ beat</span>
</a>
<p class="comment-amount">
<span class="amount pull-right">kr3,584.00</span>
</p>
Related
I want to get all the span data attribute inside the p element so that I can compare the values/text of my hidden p element
<div>
<ol class="edit-list">
<li class="edit">
<p class="hidden answer" data-answer="He loves fish tacos">He loves fish tacos</p>
<p>
<span data-original="Brad">He</span>
<span data-original="loves">loves</span>
<span data-original="fish">fish</span>
<span data-original="tactos">tactos</span>
</p>
</li>
<li class="edit">
<p class="hidden answer" data-answer="I love learning!">I love learning!</p>
<p>
<span data-original="I">I</span>
<span data-original="love">love</span>
<span data-original="learning!">learning!</span>
</p>
</li>
<li class="edit">
<p class="hidden answer" data-answer="I ate dinner">I ate dinner</p>
<p>
<span data-original="I">I</span>
<span data-original="ate">ate</span>
<span data-original="dinner">dinner</span>
</p>
</li>
</ol>
<button id="validate" >Validate</button>
</div>
Here is my JavaScript code.
<script type="text/javascript">
$(function(){
var mismatch = false;
$('ol.edit-list li').each(function(){
var p_answer = $(this).find('p').attr('data-answer');
var c_annswer = $(this).find('p').has('span').children().attr('data-original'); // I canno get all the span inside the p;
if(p_answer !== c_answer){
mismatch = true;
break;
}
}
});
</script>
$(document).ready(function() {
$(".like").click(function() {
var newValue = parseInt($(".no-like").text()) + 1;
alert(newValue);
$(".no-like").html(newValue);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="like" data-creation-id="1069347886434951" data-id="1" href="#">
<span class="no-like">35</span>
</a>
<a class="like" data-creation-id="1069347886434951" data-id="1">
<span class="no-like">3</span>
<span class="glyphicon glyphicon-heart"></span>
</a>
hey
Here there are multiple buttons. You need to add 1 value everytime it is clicked. For example: 35 to 36 and 3 to 4 .Jquery must select each button with respective value. But the code is not working even for one button.
simply use 'this' keyword to refer current instance of element
$(document).ready(function() {
$(".like").click(function() {
var newValue = +$(this).text() + 1;
if($(this).find('.no-like').length)
$(this).find('.no-like:eq(0)').text(newValue);
else
$(this).text(newValue);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="like" data-creation-id="1069347886434951" data-id="1" href="#">
35
</a>
<a class="like" data-creation-id="1069347886434951" data-id="1">
<span class="no-like">3</span>
<span class="glyphicon glyphicon-heart"></span>
</a>
$(document).ready(function() {
$(".like").click(function() {
var newValue = parseInt($(this).text()) + 1;//use this context for clicked element
alert(newValue);
$(".no-like").html(newValue);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="like" data-creation-id="1069347886434951" data-id="1" href="#">
35
</a>
<a class="like" data-creation-id="1069347886434951" data-id="1">
<span class="no-like">3</span>
<span class="glyphicon glyphicon-heart"></span>
</a>
hey
Use this context
You have to use $(this) for fetched from same element.
$(document).ready(function() {
$(".like").click(function() {
var newValue = parseInt($(this).text()) + 1;
alert(newValue);
$(".no-like").html(newValue);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<a class="like" data-creation-id="1069347886434951" data-id="1" href="#">
35
</a>
<a class="like" data-creation-id="1069347886434951" data-id="1">
<span class="no-like">3</span>
<span class="glyphicon glyphicon-heart"></span>
</a>
hey
I have a wordBox Where user will drag touch and drag to select words.
I am using touchmove eventlistener to change background/color of the word in wordBox. But touchmove only changing color/background of the text from where it started.
var COLUMNS = 20;
var ROWS = 12;
var word = ['H', 'E', 'L', 'L', 'O'];
var wordLength = word.length;
var spans = document.getElementsByTagName("span");
function select(evt) {
var id = this.id;
document.getElementById(this.id).style.background = "#ffffff";
document.getElementById(this.id).style.color = "#0070C4";
for (var i = 0; i < spans.length; i++) {
mouseMove = spans[i].addEventListener("touchmove", function(sp) {
document.getElementById(sp.toElement.id).style.background = "#ffffff";
document.getElementById(sp.toElement.id).style.color = "#0070C4";
});
}
}
function start() {
//GENERATE RANDOM WORDBOX
for (var i = 0; i < spans.length; i++) {
spans[i].innerHTML = word[Math.floor(Math.random() * wordLength)];
spans[i].addEventListener("touchmove", select);
}
}
start();
html {
background: #0070C4;
color: #fff;
}
span {
padding: 8px 6px;
}
<div id="wordBox">
<div class="column1">
<span id='r1'></span>
<span id='r2'>></span>
<span id='r3'>></span>
<span id='r4'>></span>
<span id='r5'>></span>
<span id='r6'>></span>
<span id='r7'>></span>
<span id='r8'>></span>
<span id='r9'>></span>
<span id='r10'>></span>
<span id='r11'>></span>
<span id='r12'>></span>
<span id='r13'>></span>
<span id='r14'>></span>
<span id='r15'>></span>
<span id='r16'>></span>
<span id='r17'>></span>
<span id='r18'>></span>
<span id='r19'>></span>
<span id='r20'>></span>
</div>
<div class="column2">
<span id='r21'>></span>
<span id='r22'>></span>
<span id='r23'>></span>
<span id='r24'>></span>
<span id='r25'>></span>
<span id='r26'>></span>
<span id='r27'>></span>
<span id='r28'>></span>
<span id='r29'>></span>
<span id='r30'>></span>
<span id='r31'>></span>
<span id='r32'>></span>
<span id='r33'>></span>
<span id='r34'>></span>
<span id='r35'>></span>
<span id='r36'>></span>
<span id='r37'>></span>
<span id='r38'>></span>
<span id='r39'>></span>
<span id='r40'>></span>
</div>
<div class="column3">
<span id='r41'>></span>
<span id='r42'>></span>
<span id='r43'>></span>
<span id='r44'>></span>
<span id='r45'>></span>
<span id='r46'>></span>
<span id='r47'>></span>
<span id='r48'>></span>
<span id='r49'>></span>
<span id='r50'>></span>
<span id='r51'>></span>
<span id='r52'>></span>
<span id='r53'>></span>
<span id='r54'>></span>
<span id='r55'>></span>
<span id='r56'>></span>
<span id='r57'>></span>
<span id='r58'>></span>
<span id='r59'>></span>
<span id='r60'>></span>
</div>
<div class="column4">
<span id='r61'>></span>
<span id='r62'>></span>
<span id='r63'>></span>
<span id='r64'>></span>
<span id='r65'>></span>
<span id='r66'>></span>
<span id='r67'>></span>
<span id='r68'>></span>
<span id='r69'>></span>
<span id='r70'>></span>
<span id='r71'>></span>
<span id='r72'>></span>
<span id='r73'>></span>
<span id='r74'>></span>
<span id='r75'>></span>
<span id='r76'>></span>
<span id='r77'>></span>
<span id='r78'>></span>
<span id='r79'>></span>
<span id='r80'>></span>
</div>
<div class="column5">
<span id='r81'>></span>
<span id='r82'>></span>
<span id='r83'></span>
<span id='r84'>></span>
<span id='r85'>></span>
<span id='r86'>></span>
<span id='r87'>></span>
<span id='r88'>></span>
<span id='r89'>></span>
<span id='r90'>></span>
<span id='r91'>></span>
<span id='r92'>></span>
<span id='r93'>></span>
<span id='r94'>></span>
<span id='r95'>></span>
<span id='r96'>></span>
<span id='r97'>></span>
<span id='r98'>></span>
<span id='r99'>></span>
<span id='r100'>></span>
</div>
<div class="column6">
<span id='r101'>></span>
<span id='r102'>></span>
<span id='r103'>></span>
<span id='r104'>></span>
<span id='r105'>></span>
<span id='r106'>></span>
<span id='r107'>></span>
<span id='r108'>></span>
<span id='r109'>></span>
<span id='r110'>></span>
<span id='r111'>></span>
<span id='r112'>></span>
<span id='r113'>></span>
<span id='r114'>></span>
<span id='r115'>></span>
<span id='r116'>></span>
<span id='r117'>></span>
<span id='r118'>></span>
<span id='r119'>></span>
<span id='r200'>></span>
</div>
<div class="column7">
<span id='r201'>></span>
<span id='r202'>></span>
<span id='r203'>></span>
<span id='r204'>></span>
<span id='r205'>></span>
<span id='r206'>></span>
<span id='r207'>></span>
<span id='r208'>></span>
<span id='r209'>></span>
<span id='r210'>></span>
<span id='r211'>></span>
<span id='r212'>></span>
<span id='r213'>></span>
<span id='r214'>></span>
<span id='r215'>></span>
<span id='r216'>></span>
<span id='r217'>></span>
<span id='r218'>></span>
<span id='r219'>></span>
<span id='r220'>></span>
</div>
<div class="column8">
<span id='r221'>></span>
<span id='r222'>></span>
<span id='r223'>></span>
<span id='r224'>></span>
<span id='r225'>></span>
<span id='r226'>></span>
<span id='r227'>></span>
<span id='r228'>></span>
<span id='r229'>></span>
<span id='r230'>></span>
<span id='r231'>></span>
<span id='r232'>></span>
<span id='r233'>></span>
<span id='r234'>></span>
<span id='r235'>></span>
<span id='r236'>></span>
<span id='r237'>></span>
<span id='r238'>></span>
<span id='r239'>></span>
<span id='r240'>></span>
</div>
<div class="column9">
<span id='r241'>></span>
<span id='r242'>></span>
<span id='r243'>></span>
<span id='r244'>></span>
<span id='r245'>></span>
<span id='r246'>></span>
<span id='r247'>></span>
<span id='r248'>></span>
<span id='r249'>></span>
<span id='r250'>></span>
<span id='r251'>></span>
<span id='r252'>></span>
<span id='r253'>></span>
<span id='r254'>></span>
<span id='r255'>></span>
<span id='r256'>></span>
<span id='r257'>></span>
<span id='r258'>></span>
<span id='r259'>></span>
<span id='r260'>></span>
</div>
<div class="column10">
<span id='r261'>></span>
<span id='r262'>></span>
<span id='r263'>></span>
<span id='r264'>></span>
<span id='r265'>></span>
<span id='r266'>></span>
<span id='r267'>></span>
<span id='r268'>></span>
<span id='r269'>></span>
<span id='r270'>></span>
<span id='r271'>></span>
<span id='r272'>></span>
<span id='r273'>></span>
<span id='r274'>></span>
<span id='r275'>></span>
<span id='r276'>></span>
<span id='r277'>></span>
<span id='r278'>></span>
<span id='r279'>></span>
<span id='r300'>></span>
</div>
<div class="column11">
<span id='r301'>></span>
<span id='r302'>></span>
<span id='r303'>></span>
<span id='r304'>></span>
<span id='r305'>></span>
<span id='r306'>></span>
<span id='r307'>></span>
<span id='r308'>></span>
<span id='r309'>></span>
<span id='r310'>></span>
<span id='r311'>></span>
<span id='r312'>></span>
<span id='r313'>></span>
<span id='r314'>></span>
<span id='r315'>></span>
<span id='r316'>></span>
<span id='r317'>></span>
<span id='r318'>></span>
<span id='r319'>></span>
<span id='r320'>></span>
</div>
<div class="column12">
<span id='r321'>></span>
<span id='r322'>></span>
<span id='r323'>></span>
<span id='r324'>></span>
<span id='r325'>></span>
<span id='r326'>></span>
<span id='r327'>></span>
<span id='r328'>></span>
<span id='r329'>></span>
<span id='r330'>></span>
<span id='r331'>></span>
<span id='r332'>></span>
<span id='r333'>></span>
<span id='r334'>></span>
<span id='r335'>></span>
<span id='r336'>></span>
<span id='r337'>></span>
<span id='r338'>></span>
<span id='r339'>></span>
<span id='r340'>></span>
</div>
</div>
JSFIDDLE
I also tried mouse events but getting desired results. How can i achieve this?
Use Document.elementFromPoint() with clientX and clientY to select the current element
The elementFromPoint() method of the Document interface returns the topmost element at the specified coordinates.
var COLUMNS = 20;
var ROWS = 12;
var word = ['H', 'E', 'L', 'L', 'O'];
var wordLength = word.length;
var spans = document.getElementsByTagName("span");
var started = false;
function clearAll() {
started = true;
for (var i = 0; i < spans.length; i++) {
spans[i].style.background = "";
spans[i].style.color = "";
}
}
function select(e) {
e.preventDefault();
if (started) {
var changedTouch = e.changedTouches[0];
var elem = document.elementFromPoint(changedTouch.clientX, changedTouch.clientY);
if (elem.tagName === 'SPAN') { //this condition could also be more accurate based on your specificity of the element
elem.style.background = "#ffffff";
elem.style.color = "#0070C4";
}
}
}
function mouseMoveHandler(e) {
e.preventDefault();
if (started) {
this.style.background = "#ffffff";
this.style.color = "#0070C4";
}
}
function reset() {
started = false;
}
function start() {
for (var i = 0; i < spans.length; i++) {
spans[i].innerHTML = word[Math.floor(Math.random() * wordLength)];
spans[i].addEventListener("touchstart", clearAll);
spans[i].addEventListener("mousedown", clearAll);
spans[i].addEventListener("touchmove", select);
spans[i].addEventListener("mousemove", mouseMoveHandler);
spans[i].addEventListener("touchend", reset);
spans[i].addEventListener("mouseup", reset);
}
}
start();
html {
background: #0070C4;
color: #fff;
}
span {
padding: 8px 6px;
}
<div id="wordBox">
<div class="column1">
<span id='r1'>></span>
<span id='r2'>></span>
<span id='r3'>></span>
<span id='r4'>></span>
<span id='r5'>></span>
<span id='r6'>></span>
<span id='r7'>></span>
<span id='r8'>></span>
<span id='r9'>></span>
<span id='r10'>></span>
<span id='r11'>></span>
<span id='r12'>></span>
<span id='r13'>></span>
<span id='r14'>></span>
<span id='r15'>></span>
<span id='r16'>></span>
<span id='r17'>></span>
<span id='r18'>></span>
<span id='r19'>></span>
<span id='r20'>></span>
</div>
<div class="column2">
<span id='r21'>></span>
<span id='r22'>></span>
<span id='r23'>></span>
<span id='r24'>></span>
<span id='r25'>></span>
<span id='r26'>></span>
<span id='r27'>></span>
<span id='r28'>></span>
<span id='r29'>></span>
<span id='r30'>></span>
<span id='r31'>></span>
<span id='r32'>></span>
<span id='r33'>></span>
<span id='r34'>></span>
<span id='r35'>></span>
<span id='r36'>></span>
<span id='r37'>></span>
<span id='r38'>></span>
<span id='r39'>></span>
<span id='r40'>></span>
</div>
<div class="column3">
<span id='r41'>></span>
<span id='r42'>></span>
<span id='r43'>></span>
<span id='r44'>></span>
<span id='r45'>></span>
<span id='r46'>></span>
<span id='r47'>></span>
<span id='r48'>></span>
<span id='r49'>></span>
<span id='r50'>></span>
<span id='r51'>></span>
<span id='r52'>></span>
<span id='r53'>></span>
<span id='r54'>></span>
<span id='r55'>></span>
<span id='r56'>></span>
<span id='r57'>></span>
<span id='r58'>></span>
<span id='r59'>></span>
<span id='r60'>></span>
</div>
<div class="column4">
<span id='r61'>></span>
<span id='r62'>></span>
<span id='r63'>></span>
<span id='r64'>></span>
<span id='r65'>></span>
<span id='r66'>></span>
<span id='r67'>></span>
<span id='r68'>></span>
<span id='r69'>></span>
<span id='r70'>></span>
<span id='r71'>></span>
<span id='r72'>></span>
<span id='r73'>></span>
<span id='r74'>></span>
<span id='r75'>></span>
<span id='r76'>></span>
<span id='r77'>></span>
<span id='r78'>></span>
<span id='r79'>></span>
<span id='r80'>></span>
</div>
<div class="column5">
<span id='r81'>></span>
<span id='r82'>></span>
<span id='r83'></span>
<span id='r84'>></span>
<span id='r85'>></span>
<span id='r86'>></span>
<span id='r87'>></span>
<span id='r88'>></span>
<span id='r89'>></span>
<span id='r90'>></span>
<span id='r91'>></span>
<span id='r92'>></span>
<span id='r93'>></span>
<span id='r94'>></span>
<span id='r95'>></span>
<span id='r96'>></span>
<span id='r97'>></span>
<span id='r98'>></span>
<span id='r99'>></span>
<span id='r100'>></span>
</div>
<div class="column6">
<span id='r101'>></span>
<span id='r102'>></span>
<span id='r103'>></span>
<span id='r104'>></span>
<span id='r105'>></span>
<span id='r106'>></span>
<span id='r107'>></span>
<span id='r108'>></span>
<span id='r109'>></span>
<span id='r110'>></span>
<span id='r111'>></span>
<span id='r112'>></span>
<span id='r113'>></span>
<span id='r114'>></span>
<span id='r115'>></span>
<span id='r116'>></span>
<span id='r117'>></span>
<span id='r118'>></span>
<span id='r119'>></span>
<span id='r200'>></span>
</div>
<div class="column7">
<span id='r201'>></span>
<span id='r202'>></span>
<span id='r203'>></span>
<span id='r204'>></span>
<span id='r205'>></span>
<span id='r206'>></span>
<span id='r207'>></span>
<span id='r208'>></span>
<span id='r209'>></span>
<span id='r210'>></span>
<span id='r211'>></span>
<span id='r212'>></span>
<span id='r213'>></span>
<span id='r214'>></span>
<span id='r215'>></span>
<span id='r216'>></span>
<span id='r217'>></span>
<span id='r218'>></span>
<span id='r219'>></span>
<span id='r220'>></span>
</div>
<div class="column8">
<span id='r221'>></span>
<span id='r222'>></span>
<span id='r223'>></span>
<span id='r224'>></span>
<span id='r225'>></span>
<span id='r226'>></span>
<span id='r227'>></span>
<span id='r228'>></span>
<span id='r229'>></span>
<span id='r230'>></span>
<span id='r231'>></span>
<span id='r232'>></span>
<span id='r233'>></span>
<span id='r234'>></span>
<span id='r235'>></span>
<span id='r236'>></span>
<span id='r237'>></span>
<span id='r238'>></span>
<span id='r239'>></span>
<span id='r240'>></span>
</div>
<div class="column9">
<span id='r241'>></span>
<span id='r242'>></span>
<span id='r243'>></span>
<span id='r244'>></span>
<span id='r245'>></span>
<span id='r246'>></span>
<span id='r247'>></span>
<span id='r248'>></span>
<span id='r249'>></span>
<span id='r250'>></span>
<span id='r251'>></span>
<span id='r252'>></span>
<span id='r253'>></span>
<span id='r254'>></span>
<span id='r255'>></span>
<span id='r256'>></span>
<span id='r257'>></span>
<span id='r258'>></span>
<span id='r259'>></span>
<span id='r260'>></span>
</div>
<div class="column10">
<span id='r261'>></span>
<span id='r262'>></span>
<span id='r263'>></span>
<span id='r264'>></span>
<span id='r265'>></span>
<span id='r266'>></span>
<span id='r267'>></span>
<span id='r268'>></span>
<span id='r269'>></span>
<span id='r270'>></span>
<span id='r271'>></span>
<span id='r272'>></span>
<span id='r273'>></span>
<span id='r274'>></span>
<span id='r275'>></span>
<span id='r276'>></span>
<span id='r277'>></span>
<span id='r278'>></span>
<span id='r279'>></span>
<span id='r300'>></span>
</div>
<div class="column11">
<span id='r301'>></span>
<span id='r302'>></span>
<span id='r303'>></span>
<span id='r304'>></span>
<span id='r305'>></span>
<span id='r306'>></span>
<span id='r307'>></span>
<span id='r308'>></span>
<span id='r309'>></span>
<span id='r310'>></span>
<span id='r311'>></span>
<span id='r312'>></span>
<span id='r313'>></span>
<span id='r314'>></span>
<span id='r315'>></span>
<span id='r316'>></span>
<span id='r317'>></span>
<span id='r318'>></span>
<span id='r319'>></span>
<span id='r320'>></span>
</div>
<div class="column12">
<span id='r321'>></span>
<span id='r322'>></span>
<span id='r323'>></span>
<span id='r324'>></span>
<span id='r325'>></span>
<span id='r326'>></span>
<span id='r327'>></span>
<span id='r328'>></span>
<span id='r329'>></span>
<span id='r330'>></span>
<span id='r331'>></span>
<span id='r332'>></span>
<span id='r333'>></span>
<span id='r334'>></span>
<span id='r335'>></span>
<span id='r336'>></span>
<span id='r337'>></span>
<span id='r338'>></span>
<span id='r339'>></span>
<span id='r340'>></span>
</div>
</div>
Fiddle Demo
A note of caution for clientX / clientY and document.elementFromPoint – clientX is normally the distance to the viewport, excluding the scroll offset. elementFromPoint uses the same position reference. Chrome on Android (version 50.0.2661.89) positions appear to include the scroll offset. The Internet browser on Android and Safari on iOS appear to use the correct reference point. Desktop browsers (Chrome, Firefox, IE9 & up, Edge, and Safari) appear to also use the correct reference point.
If you’re just using clientX and elementFromPoint, there shouldn’t be any issue as the same reference point is being used. I ran into trouble as I was adding the offset back in to position a new element. It worked fine until I zoomed the display on an Android phone and shifted the display towards the left. My new element was positioned correctly on most browsers, but not on Chrome on Android.
So, I'm doing a database select and bringing all the fields from a table in divs like this:
<div class="card hoverable reserva">
<div class="card-content">
<div class="cod-reserva-lbl teal-text text-lighten-2">Reservation number.</div>
<div class="reservation-code teal-text">00000000</div>
<div class="reservation-item">
<b>Car's licence plate:</b> <span class="dato">AAA-000</span>
</div>
<div class="reservation-item">
<b>Person's ID:</b> <span class="dato">00000000</span>
</div>
<div class="reservation-item">
<b>Departure:</b> <span class="dato">dd/mm/yyyy</span>
</div>
<div class="reserva-item">
<b>Arrival:</b> <span class="dato">dd/mm/yyyy</span>
</div>
<div class="reservation-item">
<b>Starting city:</b> <span class="dato">Some city</span>
</div>
<div class="reservation-item">
<b>Destination city:</b> <span class="dato">Some other city</span>
</div>
<div class="reservation-item">
<b>Price:</b> <span class="green-text dato">$XXXXXX</span>
</div>
</div>
<div class="card-action card-action-reservation">
<a href="#" class="green-text flat-small waves-effect waves-green">
<i class="left material-icons">mode_edit</i> Edit
</a>
<a href="#" class="red-text flat-small waves-effect waves-red">
<i class="left material-icons">delete</i> Delete
</a>
</div>
</div>
The script I'm currently using goes like this:
//Search filter
var $rows = $('.reservation');
//#search is the input I'm using as search bar
$('#search').keyup(function () {
var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function () {
text = $(this).text().replace(/\s+/g, ' ');
return !reg.test(text);
}).hide();
});
The problem is, if I search for "Reservation number", it will still show all of them because all of them contain "Reservation number". What I want is to be able to filter exclusively for the text inside the span.dato items. How can I achieve this?
I am trying to get product name in alert box when either image or link is clicked on product page. But there is also one buy now button available which is also currently giving the popup alert if it is clicked. I want to exclude it using jquery. Here is what I am going
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(".item").click(function (event) {
var href = $('a', this).attr("href");
var target = $('a', this).attr("target");
var text = $(this).find('.product-name').text();
event.preventDefault();
alert(text);
setTimeout(function () {
window.open(href, (!target ? "_self" : target));
}, 300);
});
});
</script>
<li class="item">
<a href="product1.php" title="Sample Product Name" class="product-image">
<span class="sale-item">Sale!</span>
<div class="cat-mouseover"></div>
<img src="/images/product1.png" alt="Sample Product Name">
</a>
<h2 class="product-name">Sample Product Name</h2>
<div class="price-box">
<p class="old-price">
<span class="price-label">For:</span>
<span class="price" id="old-price-426"> 199,-</span>
</p>
<p class="special-price">
<span class="price-label"></span>
<span class="price" id="product-price-426"> Now 139,- </span>
</p>
</div>
<div class="actions">
<button type="button" title="Buy Now" class="button btn-cart" onclick="setLocation('/checkout/cart/add/uenc/aHR0cDovL3d3dy52aXRhLm5vLw,,/product/426/')"><span><span>Buy</span></span>
</button>
</div>
</li>
<li class="item">
<a href="product1.php" title="Sample Product Name" class="product-image">
<span class="sale-item">Sale!</span>
<div class="cat-mouseover"></div>
<img src="/images/product1.png" alt="Sample Product Name">
</a>
<h2 class="product-name">Sample Product Name</h2>
<div class="price-box">
<p class="old-price">
<span class="price-label">For:</span>
<span class="price" id="old-price-426"> 199,- </span>
</p>
<p class="special-price">
<span class="price-label"></span>
<span class="price" id="product-price-426"> Now 139,- </span>
</p>
</div>
<div class="actions">
<button type="button" title="Buy Now" class="button btn-cart" onclick="setLocation('/checkout/cart/add/uenc/aHR0cDovL3d3dy52aXRhLm5vLw,,/product/426/')"><span><span>Buy</span></span>
</button>
</div>
</li>
http://jsfiddle.net/585BC/
Please advise.
Put this at the top of your callback:
if ($(event.target).hasClass("btn-cart") || $(event.target).parents(".btn-cart").length !== 0) {
return;
}
Now if the "event.target" (= where the click occured) has the class "btn-cart" or is a child of this "btn-cart", then the execution of your callback returns.
See updated fiddle: http://jsfiddle.net/585BC/2/
Just exit the event handler if you click the button:
if(($(event.target).is('.button.btn-cart')) return;
// rest of your code goes here