how to select the first div in jQuery


<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>first demo</title>
<style>
td {
color: blue;
font-weight: bold;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>

<table>
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>

<script>
$( "tr:third" ).css( "font-style", "italic" );
</script>

</body>
</html>

www.codegrepper.com
www.stackoverflow.com

how to replace all the string in javascript when the string is javascript variable


const p = 'dog dog cat rat';

const regex = /dog/gi;

console.log(p.replace(regex, 'cow'));
//if pattern is regular expression all matches will be replaced
//output: "cow cow cat rat"

function name(str,replaceWhat,replaceTo){
replaceWhat = replaceWhat.replace(/[-/\^$*+?.()|[]{}]/g, '\$&');
var re = new RegExp(replaceWhat, 'g');
return str.replace(re,replaceTo);
}

function name(str,replaceWhat,replaceTo){
var re = new RegExp(replaceWhat, 'g');
return str.replace(re,replaceTo);
}

www.codegrepper.com
www.stackoverflow.com