1

So I am currently looking for a solution to insert align="center" into a block quote. I am hitting an API and getting back a string of HTML as shown:

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Las Vegas utilities really don’t want the strip to go solar blah blah</blockquote>

What I am trying to do is add an align="center" to the blockquote in the most efficient way as shown below:

<blockquote class="twitter-tweet" align="center"><p lang="en" dir="ltr"></blockquote>

I am currently going Rambo and just replacing the string using:

myString = myString.replace("<blockquote class=\"twitter-tweet\">", "<blockquote class=\"twitter-tweet\" align=\"center\">");

But it feels as if this is a hacky solution as I am fairly new to JavaScript. Is there a better way to do it using JQuery and serializing the HTML that I am missing?

Thank you all in advance!

3
  • api.jquery.com/attr? Commented Mar 31, 2016 at 12:45
  • 2
    Use CSS, via JavaScript: blockquoteReference.style.textAlign = 'center'? Commented Mar 31, 2016 at 12:47
  • 1
    align="center" has been deprecated for quite some time now. Use CSS. Commented Mar 31, 2016 at 12:53

3 Answers 3

2

As you tell us in your tags, you're somehow using jQuery so why don't do:

$("blockquote").attr("align","center"); 

And then use it like this:

$(document).ready(function(){ //or in some other function
    $("blockquote").attr("align","center"); 
});

I think you know, that you can do this with CSS so I won't tell you again. ;)

Sign up to request clarification or add additional context in comments.

Comments

1

You should use css. But if you really want to use the attribute,

$("blockquote").attr("align","center")

Comments

-1

In the css file, add

blockquote{
text-align:center;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.