0

In my DOM element, if my CSS class starts with a specific element ,i would like to do a jquery action. for example:

Say, my DOM element looks like below.

<body>
<div id="mydiv">
<h1>This is a heading</h1>

<p class="introduce">This is a paragraph.</p>
<p class="introduction">This is another paragraph.</p>
</div>
</body>

I would like to do the action if my class name wild card(ex: intro) exists.

If wildcard classname "intro" exists   //i need the Jquery syntax for this condition
{
$(".introduce").css({ 'color': '#288054' })
$(".introduction").css({ 'color': '#fjhdhd' })
}

how to achieve this using jquery?

I can do same action for all classes that starts with or ends with specific TEXT using CSS. but here, i have to do different action in each class matching the wildcard

edited: i should have added this earlier. i would like to do this in jquery as i want to convert the css to inline styles. because these contents are going to be delivered in email. as outlook support inline styles better, we would like to use jquery. any other alternatives are also appreciated.

extractor
  • 39
  • 7
  • Try not to mix your presentation into JavaScript. Meaning, you should prefer using classes and css instead of the `.css` method. – bassxzero Jun 26 '18 at 19:12
  • no. My question is not about find classname my wildcard. it is about doing the action after finding. I can do same action for all classes that starts with or ends with specific TEXT using CSS. but here, i have to do different action in each class matching the wildcard – extractor Jun 26 '18 at 19:14
  • you try with regex also...like `str.match(/intro/g);` – Aravind S Jun 26 '18 at 19:14

0 Answers0