6 Replies - 514 Views - Last Post: 30 April 2018 - 10:21 AM

#1 user6003   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-April 18

How to replace first 3 numbers and letters of id, href and sup text?

Posted 27 April 2018 - 05:34 PM

<P><A id="article_NUMBERLETTER" HREF="#reference_NUMBERLETTER"><SUP>[NUMBERLETTER]</SUP></A></P>


The first found three numbers of an <A> tag has to be 1 and the letters has to be a.

Three numbers and letters of an <A> tag in Article are everytime the same (id, HREF, SUP).

If there are second (next A tag) not the same numbers then it has to be 2a, else the same but with b (1b) and so on.

In this example the first number and letter of id, HREF and superscripted text is 6b.

That is why the second LI tag has to be the first.

A LI tag has to be sorted alphabetically by positioning this:

from

<A id="


to

</A>textofNUMBERLETTER


How can I change this:

<P><B>Article</B></P>
<P><A id="article_6b" HREF="#reference_6b"><SUP>[6b]</SUP></A>textof6b</P>
<P><A id="article_5a" HREF="#reference_5a"><SUP>[5a]</SUP></A>textof5a</P>
<P><A id="article_6a" HREF="#reference_6a"><SUP>[6a]</SUP></A>textof6a</P>

<P><B>References</B></P>
<OL>
<LI><P>
<A id="reference_5a" HREF="#article_5a"><SUP>a</SUP></A>textof5a
</P></LI>
<LI><P>
<A id="reference_6b" HREF="#article_6b"><SUP>b</SUP></A>textof6b
</P></LI>
<LI><P>
<A id="reference_6a" HREF="#article_6a"><SUP>a</SUP></A>textof6a
</P></LI>
</OL>



into this:

<P><B>Article</B></P>
<P><A id="article_1a" HREF="#reference_1a"><SUP>[1a]</SUP></A>textof6b</P>
<P><A id="article_2a" HREF="#reference_2a"><SUP>[2a]</SUP></A>textof5a</P>
<P><A id="article_1b" HREF="#reference_1b"><SUP>[1b]</SUP></A>textof6a</P>

<P><B>References</B></P>
<OL>
<LI><P>
<A id="reference_1a" HREF="#article_1a"><SUP>a</SUP></A>textof6a
</P></LI>
<LI><P>
<A id="reference_1b" HREF="#article_1b"><SUP>b</SUP></A>textof6b
</P></LI>
<LI><P>
<A id="reference_2a" HREF="#article_2a"><SUP>a</SUP></A>textof5a
</P></LI>
</OL>


I need a code to generate this changes to minimize manual actions and the amount of time. Sometimes an article needs hundreds of changes for this. Cause of that I need a code like jQuery to generate this results. Thanks for your attention.

Is This A Good Question/Topic? 0
  • +

Replies To: How to replace first 3 numbers and letters of id, href and sup text?

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2319
  • View blog
  • Posts: 7,059
  • Joined: 15-January 14

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 27 April 2018 - 05:41 PM

You want to write Javascript code to change the document every time it's loaded in a browser? Why not just change the document once on the server?
Was This Post Helpful? 0
  • +
  • -

#3 user6003   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-April 18

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 28 April 2018 - 04:32 AM

No, it needs to be generated for one time to get the right source code of html for an article in WordPress.
Was This Post Helpful? 0
  • +
  • -

#4 user6003   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-April 18

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 28 April 2018 - 04:50 AM

Its like Wikipedia notes.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,083
  • Joined: 12-December 12

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 29 April 2018 - 01:20 AM

Quote

I need a code to generate this changes to minimize manual actions and the amount of time. Sometimes an article needs hundreds of changes for this. Cause of that I need a code like jQuery to generate this results. Thanks for your attention.

We won't write your code for you. What code have you attempted? How much do you know about Javascript and jQuery?
Was This Post Helpful? 0
  • +
  • -

#6 user6003   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-April 18

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 29 April 2018 - 04:02 AM

I'm an amateur in javascript and jquery. I think the solution of my question would be too big. But some tips of parts of the solution like 'How to find upper and lower numbers and letters under these conditions?' would be useful.
Was This Post Helpful? 0
  • +
  • -

#7 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2319
  • View blog
  • Posts: 7,059
  • Joined: 15-January 14

Re: How to replace first 3 numbers and letters of id, href and sup text?

Posted 30 April 2018 - 10:21 AM

You need to get all of the elements on the page that you need to work with. So, for example, based on your HTML above, you would need to get all anchor elements and loop through them to check their attributes. You can get the IDs, href attributes, etc, and check them however you want to see if you need to work with them, for example you could check if it has an underscore character, and if so then use String.split to get everything before and after the underscore. If you find one of the elements that is part of the text where you need to change that, then you can use the href of that element to get the ID of the corresponding element you need to change also, so you would change them in pairs.

The reason why I asked my other question is because if you're doing this in Javascript in jQuery, and assuming you're not using node.js, then that means you're trying to change the document every time it is loaded in the browser, instead of only making the changes once and saving the document. If you change the web page in your browser you can't use Javascript to save that new file. You could try to save the page using the browser but I don't know if it's going to save the changes you made to it or if it's going to save the original document.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1