2

ここで達成しようとしているのは、正規表現の影響を受ける単語の色を変更することです。

$(document).ready(function(){

  container = $("#modal_container section").text();
  hashtags = /\#\w+/g;
  var container_hash = container.match(hashtags);
  $(container_hash).css({'color':'red'}); 
  //We're grabbing the words, but how can I change the color?
  alert(container_hash);

 });

これは、より明確にするためのフィドルhttp://jsfiddle.net/vuDzC/2/です。

ありがとう

4

3 に答える 3

0
 $(function(){

  var container = $("#modal_container section");
  var htmlWrappedHashtags = container.html().replace(/\(#\w+)/g, '<span class="red">$1</span>');
  container.html(htmlWrappedHashtags);

  $(".red").css({'color':'red'}); // or better: include ".red {color: red;}" into your CSS

 });
于 2013-04-20T23:14:04.407 に答える