⚡ IS231 · Slides 1, 2 & 3 · All Exam Questions Covered

Web Technology
Complete Study Guide

HTTP Protocols · HTML · DOM · CSS

5
Chapters
4
Exam Sources
60+
Real Exam Q's
Success 🎯
01

TCP/IP & Internet Protocols

الطبقات، البروتوكولات، والبنية التحتية للإنترنت

🏗️ TCP/IP Model — الـ 4 Layers

التحويل بين الأجهزة على الإنترنت بيتم عبر 4 طبقات، كل طبقة ليها مهمة محددة:

4
Application
HTTP · SMTP · FTP
Access to network resources for users
3
Transport
TCP · UDP
Process-to-process delivery & error handling
2
Internet
IP
Move packets source → destination (routing)
1
Network Interface
Ethernet · Wi-Fi
Transmission between two devices on same network
💡 المهم فالامتحانTCP = Transport Layer. IP = Internet Layer. HTTP/SMTP = Application Layer.
🔗 TCP — Transmission Control Protocol

بيكسّر الرسالة لـ TCP Segments ويبعتها، وفي الجهة التانية يرجّعها تاني.

Communication is "end-to-end" — بيتأكد إن الـ packets وصلت بالترتيب وبدون errors.

📍 IP — Internet Protocol

بيديك عنوان رقمي (IP Address) لكل جهاز على الشبكة.

بيعمل Routing يعني بيحدد المسار من المصدر للوجهة عبر الإنترنت.

TCP + IP = Virtual connection بين source وdestination.

🌐 HTTP — HyperText Transfer Protocol

Foundation of the World Wide Web!

بينقل web pages ومحتوى من الـ web server للـ web client (browser).

يشتغل على Port 80 بشكل افتراضي
📧 SMTP — Simple Mail Transfer Protocol

بروتوكول إرسال الإيميلات! يبعت البيانات لعنوان إيميل تاني.

Application Layer يشتغل على Port 25

🔌 Well-Known TCP Port Numbers

الـ Port هو endpoint خاص بـ application معينة على الـ server. ده بيخلي في applications كتير تشتغل على نفس الجهاز.

ServicePortProtocol
HTTP (Web Server)80TCP
HTTPS (Secure Web)443TCP (TLS)
SMTP (Email Sending)25TCP
POP3 (Personal Mail Box)110TCP
FTP (File Transfer)21TCP
⚠️ من الامتحانات: HTTP uses TCP on port 80 — HTTPS uses TCP on port 443
02

HTTP Fundamentals

Resources · Request · Response · Caching · Cookies · Security

🔗 Resources & URL — Uniform Resource Locator

كل resource على الإنترنت ليه عنوان URL فريد. الـ URL بيتكون من أجزاء:

https://www.linkedin.com:443/in/neamateltazi?tab=about
https
Scheme
www.linkedin.com
Host
443
Port
/in/neamateltazi
Path
?tab=about
Query

Example 1:

https://www.linkedin.com:443/in/neamateltazi/
Scheme: https | Host: www.linkedin.com | Port: 443 (HTTPS default) | Path: /in/neamateltazi

Example 2:

http://www.google.com/search?q=computers
Scheme: http | Host: www.google.com | Port: 80 (HTTP default) | Path: /search | Query: ?q=computers
📌 Absolute vs Relative URLs
Absolute: <a href="http://www.dr-chuck.com/page2.htm"> — عنوان كامل يودي لأي مكان
Relative: <a href="page2.html"> — ملف في نفس الـ folder

🔼 HTTP Request Message

🔄 Request-Response Cycle
💻
Client (Browser)
You!
Request
Response
🖥️
Web Server
Remote machine

The client sends an HTTP request → server sends back an HTTP response. They're two different message types.

📤 Request Message Structure
HTTP REQUEST FORMAT
[method] [URL] [version]
[headers]

[body — optional, only in POST/PUT]
REAL EXAMPLE
GET http://www.google.com HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0 Chrome/120
Accept: text/html
📋 HTTP Methods — الأوامر
MethodWhat it does
GETRead data — بيجيب data. Body فاضي!
POSTInsert data — يضيف data جديدة في الـ body
PUT/PATCHUpdate data — يعدّل data موجودة
DELETEDelete data — يحذف
⚡ مهم جداً: GET بيبعت البيانات في الـ URL نفسه، مش في الـ body!
📋 Request Headers — المعلومات الإضافية
Headerالمعنىمثال
Refererالـ URL اللي منه جيت (اللي كليكت عليه)https://google.com
User-Agentمعلومات عن الـ browser/software اللي بيبعت الـ requestMozilla/5.0 Chrome/120
Acceptنوع الـ content اللي الـ client عايز يستقبلهtext/html
Accept-Languageاللغة اللي بيفضلها المستخدمar, en-US
Cookieبيانات الـ cookie اللي الـ server حطها قبل كدهsessionid=abc123
If-Modified-Sinceللـ Caching — آخر وقت جبت فيه الـ resourceWed, 25 Jan 2012
📦 POST Request — بيانات في الـ Body

لما عندك form وتبعتها بـ POST، البيانات بتتبعت في الـ body مش في الـ URL:

HTML FORM
<form action="/account/create"
      method="POST">
  <input name="firstName" />
  <input name="lastName" />
  <input type="submit" />
</form>
POST REQUEST SENT
POST /account/create HTTP/1.1
Host: server.com

firstName=Mario&lastName=Cardinal

🔽 HTTP Response Message

📥 Response Message Structure
RESPONSE FORMAT
[version] [status code] [reason]
[headers]

[body — the actual content]
REAL EXAMPLE
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 17151
Date: Sat, 14 Jan 2012 04:00:08 GMT

<html>...page content...</html>
🚦 HTTP Status Codes — دول الأهم فالامتحان!
100–199 Informational 200–299 Success 300–399 Redirection 400–499 Client Error 500–599 Server Error
CodeMeaningاللي لازم تعرفه
200 OKSuccess! طلبك اتنفذ✅ نجح كل حاجة
201 CreatedResource created successfully✅ تم الإنشاء
204 No ContentSuccess but no content to return✅ نجح بدون محتوى
301 Moved PermanentlyResource moved to new URL🔀 تحويل دايم
304 Not ModifiedUse cached version — ما اتغيرش💾 استخدم الـ cache
400 Bad RequestMalformed request من الـ client❌ الـ request غلط
401 UnauthorizedNeed to authenticate first🔑 محتاج تسجل دخول
403 ForbiddenServer reachable, access denied!🚫 وصلت للـ server لكن ممنوع
404 Not FoundResource doesn't exist🔍 مش موجود
500 Internal Server ErrorServer crashed/bug💥 خرابة في الـ server
🚨 الفرق بين 401 و 403:
401 = مش authenticated بعد (لازم تعمل login) — 403 = عملت login بس مش عندك permission
📋 Response Headers
Headerالمعنى
Content-Typeنوع الـ content (media type) — مثلاً text/html
Content-Lengthحجم الـ body بالـ bytes
Dateوقت إرسال الـ response
Expiresالتاريخ اللي بعده الـ response بيبقى "قديم"
Locationللـ redirects — العنوان الجديد
Serverاسم الـ web server
Connectionخيارات الـ connection

📂 Media Types & Caching

📄 Media Types (MIME)

الـ server بيبعت مع كل response نوع الـ content اللي بيبعته. ده بيتسمى MIME type.

MIME Typeنوعه
text/htmlصفحة HTML
image/jpegصورة JPG
text/xmlملف XML
application/jsonبيانات JSON
image/pngصورة PNG
Content Negotiation
— Client Request Header:
Accept: text/html, application/xhtml+xml

— Server Response Header:
Content-Type: text/html; charset=utf-8
💾 HTTP Caching

الـ Caching بيحفظ نسخة من الـ resource عند الـ client علشان ما يحملهاش تاني لو ما اتغيرتش.

Time-based Caching:

RESPONSE
Last-Modified: Wed, 25 Jan 2012 17:55:15 GMT
Expires: Sat, 22 Jan 2022 17:55:15 GMT
Cache-Control: max-age=315360000, public

Content-based Caching (ETag):

RESPONSE with ETag
ETag: "8e5bcd-59f-4b5dfef104d00"

Client asks "did it change?":

REQUEST → RESPONSE
— Client:
If-Modified-Since: Wed, 25 Jan 2012 17:55:15 GMT

— Server (if not changed):
HTTP/1.1 304 Not Modified
💡 Summary: "Expires" header = Response + Time-based caching — دي بتيجي في الامتحانات كتير!

🍪 Cookies & Security

🍪 HTTP Cookies

الـ Cookie هو قطعة بيانات صغيرة الـ server بيبعتها للـ client، والـ client بيبعتها تاني مع كل request.

SERVER SETS COOKIE
HTTP/1.1 200 OK
Set-Cookie: fname=Mario&lname=Cardinal; 
             expires=Monday, 09-July-2012 21:12:00 GMT
             domain=.mywebsite.com; path=/; HttpOnly
✅ استخدامات Cookies
• Session identification
• User tracking
• Preferences storage
• Often just stores a GUID (unique ID)
❌ عيوب Cookies
• Max size = 4KB فقط!
• بتتبعت مع كل request → زيادة bandwidth
• تعمل مشاكل مع الـ Caching
Never store sensitive info!
🔐 HTTP Security — Authentication Types
Typeكيف بيشتغلSecurity Level
Basic Authبيبعت username:password مشفرة بـ Base64 (مش encrypted!)❌ Insecure
Digest Authبيستخدم MD5 hashing + nonce بدل ما يبعت الـ password⚠️ Better
Windows Authبيعتمد على Windows/Active Directory protocols✅ Secure
Form-basedالأكثر شيوعاً! Login form + redirect + cookie⚠️ Needs HTTPS
BASIC AUTH FLOW
1. Client requests resource:
GET /demo/ HTTP/1.1

2. Server says: who are you?
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="localhost"

3. Client sends credentials:
Authorization: Basic bm86aXdvdWxk...
FORM-BASED AUTH
1. Unauthenticated request:
GET /demo/ HTTP/1.1

2. Redirect to login page:
HTTP/1.1 302 Found
Location: /Login.aspx?ReturnUrl=/demo/

3. After login, set cookie:
Set-Cookie: .ASPXAUTH=9694BAB...
HTTP/1.1 302 Found
Location: /demo/
🔒 HTTPS — Encryption

HTTPS = HTTP over TLS (Transport Layer Security)

بيشفّر كل البيانات المتبادلة بين الـ client والـ server.

في الـ browser:

  • URL يبدأ بـ https://
  • 🔒 Lock icon في الـ browser
  • Port 443
Authorization Summary
Authentication = إثبات الهوية (من أنا؟)
Authorization = صلاحيات الوصول (أعمل إيه؟)

403 Forbidden = Server وصلته، بس مش معاك permission
401 Unauthorized = لازم تعمل login الأول
🎯

HTTP Quiz — أسئلة حقيقية من الامتحانات

اختبر نفسك على كل اللي اتشرح

Q1 mid-2023
The values GET, POST, HEAD etc. are specified in ________ of HTTP message
A Request line
B Header line
C Entity body
D None of the previous
✅ GET/POST/HEAD هي HTTP Methods وبتيجي في أول سطر من الـ Request وهو الـ Request Line: [method] [URL] [version]
Q2 mid-2023
The ________ method leaves the message body empty.
A POST
B Send
C GET
D PUT
✅ GET بيبعت البيانات في الـ URL نفسه (Query String) — الـ body بتاعه فاضي. POST هو اللي بيبعت البيانات في الـ body.
Q3 mid-2023
Which of the following is present in BOTH an HTTP request line AND a status line?
A HTTP version number
B URL
C Method
D None
✅ Request line: GET /page HTTP/1.1 — Status line: HTTP/1.1 200 OK — الـ HTTP version موجود في الاتنين!
Q4 mid-2023
________ protocol is used for sending and receiving e-mails
A FTP
B SMTP
C TELNET
D HTTP
✅ SMTP = Simple Mail Transfer Protocol — خصيصاً للإيميلات. HTTP للـ web, FTP لنقل الملفات.
Q5 mid-2023
An HTTP request message ALWAYS contains ________
A A header and a body
B A request line and a header
C A status line, a header, and a body
D None
✅ Request line (method+URL+version) وHeaders = موجودين دايماً. الـ Body ممكن يكون فاضي (زي GET). Status line دي للـ Response مش الـ Request.
Q6 mid-2022 / mid-2023
The ________ HTTP request header identifies the URL that was clicked to reach the page (referring page URL)
A User-Agent
B Referer
C Accept
D Cookie
✅ Referer = العنوان اللي جيت منه. User-Agent = معلومات الـ browser. Accept = نوع الـ content المقبول.
Q7 mid-2022
A cookie is created by ________
A Server
B Client
C Host
D None
✅ الـ Server هو اللي بيعمل الـ Cookie ويبعتها للـ client عن طريق Set-Cookie header. الـ client بس بيحفظها ويبعتها مع كل request.
Q8 mid-2022
HTTP uses the services of ________ on well-known port ________
A TCP, 80
B HTTP, 80
C TCP, 443
D HTTPS, 443
✅ HTTP = TCP + Port 80. HTTPS = TCP + TLS + Port 443. الـ HTTP مش بروتوكول، هو مبني فوق TCP.
Q9 mid-2022
HTTPS uses the services of ________ on well-known port ________
A TCP, 443
B HTTPS, 443
C TCP, 80
D HTTP, 443
✅ HTTPS = HTTP over TLS, runs on TCP port 443. دي مش بروتوكول منفصل، هي HTTP + encryption layer.
Q10 final-2024 / mid-2022
"Expires: Tuesday, 17 Dec 2020 18:30 GMT" is a _________ header denoting _________
A Request, time-based caching
B Response, content-based caching
C Request, content-based caching
D Response, time-based caching
✅ Expires بيييجي في الـ Response (مش الـ Request) وهو مثال على Time-based Caching — بيقولك لحد إمتى الـ content صالح.
Q11 mid-2022
Using authorization, having a response of status 403 means that ________
A Server is reachable but the user is NOT authorized
B Server is not reachable and user is not authorized
C Server is reachable and no content available
D None
✅ 403 Forbidden = وصلت للـ server وفهم طلبك، لكنه رفض يديك الـ resource عشان مش عندك permission.
Q12 mid-2022
Status code 220 denotes a successful HTTP Response. True or False?
A True
B False
✅ FALSE! النجاح من 200 لـ 299 فقط. مفيش كود اسمه 220 في HTTP. الـ 200 OK هو اللي يدل على النجاح.
Q13 final-2025
An HTTP response content type denotes:
A The media type of the content
B The image size of the content
C The text size of the content
D None of the answers
✅ Content-Type header بيحدد الـ media type (MIME type) زي text/html أو application/json.
03

HTML — HyperText Markup Language

Structure · Tags · Elements · Forms · HTML5

🏗️ Structure of an HTML Document
HTML DOCUMENT SKELETON
<!DOCTYPE html>
<html>
  <head>
    <!-- Metadata: not visible on page -->
    <title>Page Title</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" 
          href="style.css">
  </head>
  <body>
    <!-- Visible page content -->
    <h1>Hello World</h1>
  </body>
</html>
📌 المهم:
<head> = Metadata عن الصفحة (مش مرئية)
<body> = كل اللي بيظهر للمستخدم
<title> = اسم الصفحة في الـ browser tab
<meta> = معلومات للـ browser/search engines
⚡ من الامتحان: Tags and texts that are NOT directly displayed are written in the <head> section.
💡 Tim Berners-Lee = Father of the WWW! أسّس W3C في MIT.

🏷️ HTML Tags & Elements

🏷️ Tag Basics — الأساسيات
<h1> Start Tag Hello World Content </h1> End Tag (has /)
<img src = "photo.png" /> Self-closing tag (no end tag needed)
⚠️ Rules for valid HTML: Tags must be lowercase · Attributes in quotes · All tags closed
✍️ HTML Formatting Elements — دول بيجوا كتير في الامتحانات!
TagEffectExample
<b>Bold textBold
<strong>Important text (bold)Important
<i>Italic textItalic
<em>Emphasized (italic)Emphasized
<mark>Highlighted textMarked
<del>StrikethroughDeleted
<ins>UnderlinedInserted
<sub>Subscript (H2O)H2O
<sup>Superscript (x2)x2
<br>Line break (empty tag)
<hr>Horizontal rule
EXAM COMMON EXAMPLES
NO2 (subscript 2):
<p>NO<sub>2</sub></p>

H2O (subscript 2):
<p>H<sub>2</sub>O</p>

x² (superscript 2):
<p>x<sup>2</sup></p>

Strike+Underline:
<p><del>Hello</del>
    <ins>Hi</ins></p>

Highlighted:
<p><mark>Important</mark></p>
🚨 Empty Elements (Self-closing):
<br>, <hr>, <img>, <meta>, <link>
دي مش محتاجة closing tag!
📝 Headings, Paragraphs & Styles
HEADINGS h1–h6
<h1>Biggest Heading</h1>
<h2>Heading 2</h2>
<h6>Smallest Heading</h6>
INLINE STYLES
Background color:
<body style="background-color:yellow;">

Text color (both are correct!):
<p style="color:red;">Red text</p>
<p style="color:#ff0000;">Also red!</p>

Font:
<h1 style="font-family:verdana;">
💡 من الامتحان: color:red = color:#ff0000 — كلاهما صح!

🔗 Links · Images · Lists · Tables

🔗 HTML Links
ANCHOR TAG
Absolute link:
<a href="http://www.google.com">
  Google
</a>

Relative link:
<a href="page2.html">
  Page 2
</a>

a = anchor, href = hypertext reference

Links can wrap around images too! <a href="..."><img src="..."></a>
🖼️ Images & Attribute
IMAGE TAG
<img 
  src="photo.png"
  alt="My Photo"
  style="width:200px"
/>

src = path to image (مش href ومش link!)

alt = نص بديل لو الصورة ما اتحملتش

📋 Lists
ORDERED vs UNORDERED
Unordered (bullets) → <ul>:
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

Ordered (numbers) → <ol>:
<ol>
  <li>First</li>
  <li>Second</li>
</ol>
📊 Tables
TABLE STRUCTURE
<table>
  <tr>  <!-- table row -->
    <th>Make</th>  <!-- header cell -->
    <th>Model</th>
  </tr>
  <tr>
    <td>Ford</td>  <!-- data cell -->
    <td>Edge</td>
  </tr>
</table>

🚀 HTML5 New Features

📝 New Input Types

HTML5 introduced new <input> types: email, date, time, color, range...

If browser doesn't support → treats as normal text input.

💾 Web Storage

localStorage: permanent (cross-sessions), up to 5MB

sessionStorage: temp, cleared when tab closes

Better than cookies! Data NOT sent to server with each request.

📱 Application Cache

Lets browser save HTML + resources locally for offline use.

Reduces HTTP requests + server load. Faster loading!

🆚 Cookies vs Web Storage — Comparison
FeatureCookiesWeb Storage
Max Size4KB5MB
Sent to server?Yes, every requestNo, stays local
ExpiryCan be setLocal = forever / Session = tab close
🎯

HTML Quiz — أسئلة حقيقية من الامتحانات

كل الأسئلة من امتحانات Cairo University

Q1 mid-2023
Which of the following are called empty HTML elements?
A <p>
B <body>
C <br>
D None of the previous
✅ Empty (self-closing) elements مش ليهم content ولا closing tag. مثلاً <br>, <hr>, <img>. <p> و<body> ليهم content وclosing tags.
Q2 mid-2023
What is the correct HTML for adding a background color?
A <background> yellow</background>
B <body style="background-color:yellow;">
C <body bg="yellow">
D None
✅ الطريقة الصحيحة هي style attribute مع background-color property. لا يوجد bg attribute أو background tag.
Q3 mid-2023
Choose the correct HTML element to define important text
A <i>
B <b>
C <strong>
D <important>
✅ <strong> = semantic tag للنص المهم (Important text). <b> = visual bold فقط بدون semantic meaning. <i> = italic.
Q4 mid-2023
Which of these elements are all <table> elements?
A <table> <head> <tfoot>
B <thead> <body> <tr>
C <table> <tr> <td>
D <table> <tr> <tt>
✅ table elements: <table> (container), <tr> (row), <td> (data cell), <th> (header cell). <head> و<body> دول document elements مش table elements.
Q5 mid-2022
What is the difference between an opening tag and a closing tag?
A Opening tag has a /
B Closing tag has /
C There is no difference
✅ Opening = <h1> — Closing = </h1> (الـ / في الـ closing tag)
Q6 mid-2022
Who is known as the father of the WWW?
A Robert Cailiau
B Time Thompson
C Berners Charles
D Tim Berners-Lee
✅ Tim Berners-Lee أسّس الـ WWW وأسّس W3C في MIT/CERN.
Q7 mid-2022
How can you make a bulleted list WITH NUMBERS?
A <dl>
B <bl>
C <ol>
D <ul>
✅ <ol> = Ordered List = أرقام. <ul> = Unordered List = نقاط (bullets). <dl> = Definition List.
Q8 final-2024
Which is the correct HTML statement to display H₂O in a paragraph?
A <p>H<sup>2</sup>O</p>
B <p>H<ins>2</ins>O</p>
C <p>H<sub>2</sub>O</p>
D None
✅ H₂O = الـ 2 تحت = subscript = <sub>. <sup> ده superscript (فوق) زي x².
Q9 final-2024
Which is correct to display "Hello" struck-through and "Hi" underlined?
A <p><cut>Hello</cut><ins>Hi</ins></p>
B <p><del>Hello</del><ins>Hi</ins></p>
C <del>Hello</del><mark>Hi</mark>
D None
✅ <del> = strikethrough (خط فوق الكلمة). <ins> = underline. <cut> مش موجود في HTML.
Q10 final-2024
Which attribute specifies the path to the image?
A href
B link
C src
D All of the above
✅ <img src="..."> — src = source = المسار للصورة. href بتستخدمها في <a> للروابط.
Q11 final-2024
Which is the correct way of creating a hyperlink in HTML?
A <a>www.google.com</a>
B <a href="www.google.com" google /a>
C <a href="www.google.com"> google </a>
D <a link="www.google.com"> google </a>
✅ الـ <a> tag محتاجة href attribute (مش link). والـ text اللي بين التاجين هو اللي بيظهر للمستخدم.
Q12 final-2024
Which HTML tag is used to define highlighted text?
A <highlight>
B <mark>
C <p style="color:red;">
D None
✅ <mark> = highlighted text (زي الـ yellow highlighter). <highlight> مش موجود في HTML.
Q13 mid-2023
Which is the correct HTML statement to display NO₂ in a paragraph?
A <p>NO<sup>2</sup></p>
B <p>NO<ins>2</ins></p>
C None of the previous
D <p>NO<sub>2</sub></p>
✅ NO₂ = الـ 2 تحت = <sub>. الإجابة الصحيحة d لكن في الامتحان ترتيب الخيارات ممكن يتغير. المهم <sub> للـ subscript (تحت).
04

HTML DOM — Document Object Model

Tree · Nodes · Finding · Modifying · Events

🌳 DOM Tree — Every HTML element is a NODE

الـ DOM بيحوّل الـ HTML document لـ tree of objects. كل element وكل text وكل attribute = node.

JavaScript ممكن يوصل لأي node، يعدّله، يضيف جديد، أو يمسح.

Document
└── <html> (Root)
├── <head>
└── <title>
└── "My title" (text)
└── <body>
├── <h1>
└── "My header" (text)
└── <a href="...">
└── "My link" (text)
📌 Node Types — مهمة في الامتحانات!

nodeType = 1 → Element node (<h1>, <p>...)
nodeType = 3 → Text node ("Hello World")
nodeType = 2 → Attribute node

nodeName of element = tag name ("H1", "P")
nodeName of text node = "#text"

nodeValue of element = null!
nodeValue of text = actual text
⚡ Node Relationships:
parent, child, siblings
parentNode · firstChild · lastChild
previousSibling · nextSibling · childNodes
🔍 Exam HTML — تحليل مهم!

دي الـ HTML اللي بتيجي في الامتحانات — فهمها كويس!

EXAM HTML SNIPPET (mid-2023 / final-2024)
<h2 id="id1">Hello World</h2>   ← NOT a <p>
<p>Welcome</p>                   ← p #1
<div>
  <p>Paragraph 1.</p>          ← p #2
  <p>Paragraph 2.</p>          ← p #3
  <section><p>Paragraph 3.</p></section>  ← p #4
</div>
<p>Paragraph 4.</p>             ← p #5
<p>Paragraph 5.</p>             ← p #6
<script>
  const my = document.getElementsByTagName("p");
  document.getElementById("id1").innerHTML = my.length;
</script>
💡 التحليل:
• عدد <p> elements = 6 → my.length = 6
• h2 innerHTML سيتغير من "Hello World" لـ 6
• إجابة "None of the previous" = الصح (مش 5!) — الجواب الصح 6

🔍 Finding HTML Elements

🔍 5 Ways to Find Elements
FINDING ELEMENTS — All 5 Methods
// 1. By ID — fastest, returns ONE element
document.getElementById('title');

// 2. By class name — returns live HTMLCollection
document.getElementsByClassName('note');

// 3. By tag name — returns HTMLCollection
document.getElementsByTagName('p');

// 4. querySelector — CSS selector, FIRST match only
document.querySelector('#fruits > li');

// 5. querySelectorAll — CSS selector, NodeList (all matches)
document.querySelectorAll('.note');
⚡ مهم: getElementById يرجع element واحد. getElementsByTagName/ClassName ترجع HTMLCollection (زي array).
📊 Node Properties — دول بيجوا كتير في الامتحانات!
NODE PROPERTIES EXAMPLES
const h2 = document.getElementById("id1");
// h2 = <h2 id="id1">Hello World</h2>

h2.nodeType;          // → 1  (element node)
h2.nodeName;          // → "H2" (tag name, READ-ONLY)
h2.nodeValue;         // → null (elements have null!)
h2.innerHTML;         // → "Hello World"

h2.firstChild;        // → text node "Hello World"
h2.firstChild.nodeType;  // → 3  (text node)
h2.firstChild.nodeName;  // → "#text"
h2.firstChild.nodeValue; // → "Hello World"  ← EQUIVALENT to innerHTML!

// So: h2.innerHTML === h2.firstChild.nodeValue

✏️ Modifying HTML Elements

✏️ Changing Content & Styles
MODIFYING ELEMENTS
const h1 = document.getElementById('title');

// Change TEXT content (safe, no XSS risk)
h1.textContent = 'New Title';

// Change with HTML (renders tags)
h1.innerHTML = 'Hello <em>World</em>';

// Change style
h1.style.color = 'tomato';
h1.style.fontSize = '3rem';

// Change attribute
const link = document.querySelector('a');
link.setAttribute('href', 'https://example.com');
🚨 innerHTML vs innerText — Security!
innerHTML = renders HTML tags (can execute scripts → XSS attack!)
innerText = plain text only (SAFE)
Always use innerText when dealing with user input!

➕ Add/Delete Elements & Events

Add & Delete Elements
DOM MANIPULATION
// Create new element
const li = document.createElement('li');
li.textContent = 'Buy groceries';

// appendChild → adds at END (last child)
const ul = document.getElementById('list');
ul.appendChild(li);

// insertBefore(new, reference)
ul.insertBefore(newEl, ul.firstElementChild);

// Remove element
ul.removeChild(li);  // old way
li.remove();          // modern

// Replace element
ul.replaceChild(newEl, oldEl);
🎯 Event Handling
EVENTS
// Modern way (preferred):
btn.addEventListener('click', handler);

// Old way (not recommended):
btn.onclick = function() { alert('hello'); };

// Common events:
'click'          // mouse click
'dblclick'       // double click
'mouseenter'     // hover in
'keydown'        // key press
'DOMContentLoaded'  // page ready

// Event object:
btn.addEventListener('click', (e) => {
  e.target;             // element clicked
  e.preventDefault(); // stop default
  e.stopPropagation(); // stop bubbling
});
🧩 Modern DOM APIs (ES6+)
MODERN APIS
// classList API (better than className):
box.classList.add('active');
box.classList.remove('active');
box.classList.toggle('active');  // add if missing, remove if present
box.classList.contains('active'); // true/false

// DocumentFragment (batch insertion, ONE reflow):
const frag = document.createDocumentFragment();
items.forEach(item => frag.appendChild(createRow(item)));
table.appendChild(frag);

// dataset API:
// <button data-user-id="42" data-role="admin">
btn.dataset.userId; // "42"
btn.dataset.role;   // "admin"
🎯

DOM Quiz — أسئلة حقيقية من الامتحانات

DOM, Node Types, Finding & Modifying

Q1 mid-2023
Everything in HTML DOM is treated as
A Attributes
B Nodes
C Arrays
D Elements
✅ في الـ DOM، كل حاجة = node! Elements, text, attributes, comments — كلها nodes في الـ tree.
Q2 mid-2023
In HTML DOM, getElementById is a ________ while innerHTML is a ________
A Object, method
B Method, node
C Node, property
D Method, property
✅ getElementById() = method (ليه parentheses وبتستدعيه). innerHTML = property (بتوصل له مباشرة بالـ dot).
Q3 mid-2023 / final-2024
In HTML DOM, which of the following properties are read-only?
A nodeName
B nodeValue
C nodeName and nodeValue
D None of the above
✅ nodeName = read-only (مش تقدر تغيره). nodeValue = read/write (تقدر تغير قيمة text node بيه).
Q4 mid-2023
Which method is used to add a new element as the LAST child of the parent?
A addChild()
B createChild()
C appendChild()
D None
✅ appendChild() = يضيف الـ element في آخر الـ parent. insertBefore() = يضيفه قبل element معين.
Q5 mid-2023
Which commands will add element x BEFORE element y (same parent e)?
A e.insertBefore(y, x)
B e.insertBefore(x, y)
C e.insertAfter(x, y)
D e.insertAfter(y, x)
✅ e.insertBefore(newEl, referenceEl) — الـ new element الأول، والـ reference (اللي هيجي بعده) التاني. مفيش insertAfter في standard DOM.
Q6 final-2024
Which JavaScript method is used to access an HTML element by id?
A getElementById()
B getElement(id)
C getElementById(id)
D elementById(id)
✅ الـ method الصحيح هو document.getElementById(). اسم الـ method هو getElementById وبتديه الـ id كـ argument.
Q7 final-2024
Which property is used to define the HTML content to an HTML element with a specific id?
A innerText
B innerContent
C elementText
D innerHTML
✅ innerHTML = بيديك أو بيغير الـ HTML content. innerText = plain text فقط. innerContent مش موجود.
Q8 mid-2023 / final-2024
To get the TEXT of h2, document.getElementById("id1").innerHTML is equivalent to:
A document.getElementById("id1").text
B document.getElementById("id1").firstChild.nodeValue
C document.getElementById("id1").nodeValue
D None
✅ innerHTML = firstChild.nodeValue! الـ firstChild بيرجع الـ text node، وnodeValue بيرجع قيمة الـ text node.
Q9 mid-2023 / final-2024
Based on the exam HTML (6 <p> elements), the content of h2 element will be presented as:
A Hello World
B Hello World 6
C 5
D None of the previous (it's 6)
✅ my = getElementsByTagName("p") يرجع كل 6 p elements. my.length = 6. فـ h2.innerHTML = 6. مش 5!
Q10 mid-2023 / final-2024
Using document.getElementById("id1").nodeType will return:
A 1
B 3
C Element node (text)
D Text node (text)
✅ nodeType = 1 للـ Element nodes. nodeType = 3 للـ Text nodes. بترجع رقم مش كلمة!
Q11 mid-2023
Using document.getElementById("id1").nodeValue will return:
A Hello World
B 1
C Null
D 3
✅ Element nodes ليهم nodeValue = null! بس Text nodes ليهم nodeValue = النص الفعلي. عشان تاخد النص: firstChild.nodeValue أو innerHTML.
Q12 mid-2023
Using document.getElementById("id1").firstChild.nodeType will return:
A Hello World
B 2
C 3
D Null
✅ firstChild بترجع الـ text node اللي جوا h2. الـ text node بتاعه nodeType = 3.
Q13 final-2025
What will be the output of "document.getElementById("id1").firstChild.nodeName;"?
A 1
B 2
C #text
D None
✅ nodeName بتاع text node دايماً = "#text". وطبعاً بترجع string مش رقم!
Q14 final-2025
How do you remove an element from the DOM?
A element.delete()
B element.destroy()
C element.remove()
D element.clear()
✅ element.remove() = Modern way. أو parent.removeChild(element) = Old way. delete وdestroy مش موجودين.
05

CSS — Cascading Style Sheets

Syntax · Selectors · Properties · Specificity

🎨 CSS Basics — Syntax
CSS RULE ANATOMY
h1 {                    /* ← Selector */
  color: red;          /* ← Declaration */
  font-size: 24px;     /* ← Declaration */
}                        /* property: value */
Selector = h1 (من تستهدف)
Declaration = color: red (الخاصية والقيمة)
Rule = كل الـ block
📍 3 Ways to Apply CSS
CSS LOCATIONS
1. Inline (highest priority):
<p style="color:red;">

2. Internal (in <head>):
<style>
  p { color: red; }
</style>

3. External (separate file):
<link rel="stylesheet" 
      type="text/css"
      href="style.css">
⚡ Priority (Highest → Lowest):
1. Inline (style attribute) — highest!
2. Internal (<style> in head)
3. External (separate .css file)
4. Browser default — lowest!

🎯 CSS Selectors — الأصعب في الامتحانات!

🎯 Selectors Reference
Selectorالمعنىمثال
Eكل elements من نوع Ep { }
.classelements بـ class معين.note { }
#idelement بـ id معين#title { }
E.classelements E بـ specific classp.center { }
E > FF اللي هو direct child لـ E فقطdiv > p { }
E ~ Fكل F اللي هم siblings بعد Ediv ~ p { }
E + Fالـ F الأولانية immediately بعد Ediv + p { }
E[attr=val]E عنده attribute بقيمة محددةa[target=_blank]
E[attr^=val]attr يبدأ بـ vala[href^="https"]
E[attr$=val]attr ينتهي بـ vala[href$=".pdf"]
E:first-childE لو كان أول child لـ parent بتاعهp:first-child { }
E:hoverE لما يكون hovereda:hover { }
E:enabledE لما يكون enabledinput:enabled
E:emptyE اللي مفيش ليه childrenp:empty { }
🧪 CSS Selector Analysis — من الامتحانات!

دي الـ HTML اللي بيجي في أسئلة الـ CSS selectors:

EXAM HTML FOR CSS QUESTIONS
<h2>CSS Selector</h2>                        ← first child of body
<p>Hello I am Here:</p>                   ← p#1, 2nd child
<p>Hello I am Here: Paragraph 2</p>        ← p#2
<p> Hello I am Here: P3</p>              ← p#3
<a href="https://www.w3schools.com">w3schools</a>
<a href="http://www.disney.com" target="_blank">disney</a>
<a href="http://www.wikipedia.org" target="_top">wiki</a>
🔍 p:first-child → 0 elements!
"p اللي هو أول child لـ parent بتاعه"
في الـ body، أول child هو <h2> مش <p>
∴ مفيش p هو first-child → 0 elements
✅ a[target=_blank] → 1 element
بس disney.com عنده target="_blank"
wikipedia عنده target="_top" مش _blank
EXAM HTML FOR div > p AND div ~ p
<p>Welcome</p>                          ← p before div
<div>
  <p>Paragraph 1.</p>                ← direct child of div ✓
  <p>Paragraph 2.</p>                ← direct child of div ✓
  <section><p>Paragraph 3.</p></section>  ← NOT direct child ✗
</div>
<p>Paragraph 4.</p>                     ← sibling after div ✓
<p>Paragraph 5.</p>                     ← sibling after div ✓
div > p → 2 elements
Only P1, P2 are direct children. P3 is inside <section>.
div ~ p → 2 elements
P4, P5 are siblings after the div. P before div doesn't count.
div + p → 1 element
Only P4 (immediately next sibling after div).

📦 Box Model & CSS Properties

📦 CSS Box Model
margin (space OUTSIDE)
border
padding (space INSIDE)
Content
📌 المهم فالامتحان:

Margin = مسافة خارج الـ element (بين العنصر وجيرانه)
Padding = مسافة داخل الـ element (بين الـ content والـ border)
Border = الـ border بتاع الـ element

السؤال "space INSIDE the element" → Padding
السؤال "space between elements" → Margin
OTHER KEY PROPERTIES
background-color: yellow;
background-image: url('img.png');
background-position: center top;
background-attachment: fixed;
font-size: 16px;
font-family: Arial, sans-serif;
color: #ff0000;  /* = red */
🎯

CSS Quiz — أسئلة حقيقية من الامتحانات

Selectors · Priority · Properties

Q1 mid-2023
How do you add a background color for ALL <h1> elements?
A h1.all {background-color:#ffffff}
B all.h1 {background-color:#ffffff}
C h1 {background-color:#ffffff}
D h1:background-color=#ffffff;
✅ CSS rule للـ h1 element: selector {property: value}. الـ colon (:) بين property والـ value، والـ semicolon (;) في الآخر.
Q2 mid-2023 / mid-2022
Which of the following is the correct way to apply CSS Styles?
A Inside an HTML element (inline)
B Inside the <head> section (internal)
C In an external CSS file
D All of the mentioned
✅ الـ 3 طرق كلها صح: Inline (في الـ element)، Internal (في <head>)، External (ملف منفصل).
Q3 mid-2023
Which of the following CSS styles has the HIGHEST priority?
A External style
B Internal style
C Inline style
D Browser default
✅ Inline > Internal > External > Browser default. الـ inline style ليه أعلى أولوية عشان هو أكثر specific.
Q4 final-2024
In CSS, "color:red" can be called as:
A Selector
B Declaration
C Rule
D Value
✅ Declaration = property + value زي "color:red". الـ Rule = selector + declarations. الـ Selector = h1. القيمة = red.
Q5 final-2024
External CSS style has the highest priority. True or False?
A True
B False
✅ FALSE! Inline style هو الأعلى. External CSS هو الأقل (غير البrowser default).
Q6 final-2024
Which selector selects elements of type E with a particular class value?
A E~F
B E.class
C E#class
D Class(E)
✅ p.center = كل <p> elements اللي ليها class="center". E#id = element بـ id. E~F = siblings.
Q7 final-2024
Which selector selects all elements of E that have attribute (attr) that ENDS WITH a given value?
A E[attr$=value]
B E[attr^=value]
C E[attr~=value]
D None
✅ $ = ends with. ^ = starts with. ~ = contains word. *= contains substring.
Q8 final-2024
Which selector selects an element that has NO children?
A :nochild
B :empty
C :no-child
D None
✅ :empty = element مفيهوش children (حتى text nodes). :nochild و:no-child مش موجودين.
Q9 mid-2023 / final-2024
Based on the exam HTML, using "div > p", how many p elements will be styled?
A 3
B 2
C 5
D 6
✅ div > p = direct children only. P1 وP2 هم direct children. P3 جوا <section> (مش direct child). Answer = 2 (الخيار B).
Q10 mid-2023 / final-2024
Based on the exam HTML, using "div ~ p", how many p elements will be styled?
A 3
B 2
C 5
D 6
✅ div ~ p = كل <p> siblings بعد الـ div. P4 وP5 جايين بعد الـ div. P welcome قبل الـ div مش بيتحسب. Answer = 2.
Q11 — final-2024
In a[target=_blank], the [target=_blank] is called:
A Attribute selector
B Anchor selector
C Pseudo element selector
D None
✅ [target=_blank] = Attribute selector — بيستهدف elements اللي عندهم attribute معين بقيمة معينة.
Q12 final-2024
To change the color of <a> elements to yellow when the mouse moves OVER it:
A a::hover {background-color: yellow;}
B a:hover {background-color: yellow;}
C a:link {background-color: yellow;}
D a:active {background-color: yellow;}
✅ :hover = pseudo-class للـ hover state. بـ single colon مش double. ::hover مش موجود. :link = unvisited link. :active = while clicking.
Q13 final-2024 / final-2025
Which CSS property is used to change the space INSIDE an element (between content and border)?
A margin
B spacing
C padding
D border
✅ padding = المسافة بين الـ content والـ border (جوا العنصر). margin = المسافة بره العنصر. spacing مش CSS property.
Q14 final-2025
The CSS background-attachment property is used to specify that the background image should scroll or be fixed. True or False?
A True
B False
✅ TRUE! background-attachment: fixed = الخلفية ثابتة مكانها حتى لو scrolled. background-attachment: scroll = بتتحرك مع الـ scroll.
Q15 final-2025
Based on the exam HTML, using "p:first-child", how many p elements will be styled?
A 1
B 0
C 3
D 6
✅ p:first-child = <p> اللي هو أول child بتاع parent بتاعه. في body، أول child هو <h2> مش <p>. ∴ 0 عناصر! في الـ div أول child هو <p> Paragraph 1 — لكن ده مش p:first-child لـ body. خليك دقيق!
📋

Quick Reference Cheat Sheet

ملخص سريع لكل المنهج — حفظه قبل الامتحان!

🏗️ TCP/IP & Protocols

TCP/IP Layers
4 Layers: Application → Transport → Internet → Network Interface
Application Layer
HTTP, SMTP, FTP — provides access to network resources for users
Transport Layer
TCP, UDP — process-to-process delivery & error handling
Internet Layer
IP — move packets from source to destination (routing)
Network Interface
Ethernet, Wi-Fi — transmission between two devices on same network
TCP
Breaks messages into segments, end-to-end reliable delivery, ensures order
IP
Assigns numeric address (IP Address), handles routing between networks
HTTP Port
80 (TCP)
HTTPS Port
443 (TCP + TLS)
SMTP Port
25 — Email sending
POP3 Port
110 — Personal mailbox
FTP Port
21 — File transfer

🌐 HTTP Essentials

URL Parts
scheme://host:port/path?query — مثال: https://www.site.com:443/page?q=test
GET
Read data — body empty! data in URL (Query String)
POST
Insert data — data in body
PUT / PATCH
Update existing data
DELETE
Delete data
Request Line
[method] [URL] [version] — مثال: GET /page HTTP/1.1
Status Line
[version] [status code] [reason] — مثال: HTTP/1.1 200 OK
Request Always Has
Request line + headers (body is optional — empty in GET)
HTTP Version
Present in BOTH request line AND status line
Referer Header
Request header — the URL that was clicked to reach this page
User-Agent
Request header — info about the browser/software
Content-Type
Response header — the media type (MIME) of the content

🚦 HTTP Status Codes

200 OK
✅ Success — request completed
201 Created
✅ Resource created successfully
204 No Content
✅ Success but no body to return
301 Moved Permanently
🔀 Resource moved to new URL
304 Not Modified
💾 Use cached version — content didn't change
400 Bad Request
❌ Malformed request from client
401 Unauthorized
🔑 Need to authenticate (login first!)
403 Forbidden
🚫 Server reachable, user authenticated, but NO permission
404 Not Found
🔍 Resource doesn't exist
500 Internal Server Error
💥 Server crashed/bug
401 vs 403
401 = مش authenticated (login!) | 403 = authenticated بس مش authorized

💾 Caching & Cookies

Expires Header
Response + Time-based caching — بتيجي في الامتحانات كتير!
ETag
Content-based caching — hash of the content
If-Modified-Since
Request header — client asks "did it change since this date?"
304 Not Modified
Server response = "no changes, use your cached copy"
Cookie Created By
Server (via Set-Cookie header) — client just stores & sends back
Cookie Max Size
4KB — sent with every request = bandwidth overhead
Web Storage
5MB — NOT sent to server — better than cookies
localStorage
Permanent (persists across sessions)
sessionStorage
Temporary (cleared when tab closes)

🔐 Security & Authentication

HTTPS
HTTP over TLS — encrypted — port 443
Basic Auth
Base64 encoded (NOT encrypted!) — ❌ Insecure
Digest Auth
MD5 hashing + nonce — ⚠️ Better
Form-based Auth
Login form → redirect → cookie — most common. ⚠️ Needs HTTPS
Authentication
إثبات الهوية — Who are you?
Authorization
صلاحيات الوصول — What can you do?

🏷️ HTML Quick Ref

<head>
Metadata — NOT visible on page (title, meta, link, style)
<body>
Visible page content
<title>
Browser tab text — inside <head>
Empty Elements
<br>, <hr>, <img>, <meta>, <link> — no closing tag needed
<strong>
Important (semantic bold) — NOT <b> which is just visual
<em>
Emphasized (semantic italic) — NOT <i>
<mark>
Highlighted text — <highlight> مش موجود!
<del>
Strikethrough (deleted text)
<ins>
Underlined (inserted text)
<sub>
Subscript — H2O, NO2
<sup>
Superscript — x2
<a href="...">
Hyperlink — href = hypertext reference
<img src="...">
Image — src NOT href! alt = alternative text
<ol>
Ordered list (numbers)
<ul>
Unordered list (bullets)
Table Elements
<table> → <tr> (row) → <th> (header) / <td> (data)
Tim Berners-Lee
Father of the WWW — founded W3C at MIT

🌳 DOM Quick Ref

DOM
Document Object Model — HTML → tree of objects. Everything = Node
nodeType = 1
Element node (<h1>, <p>, <div>...)
nodeType = 2
Attribute node
nodeType = 3
Text node ("Hello World")
nodeName (element)
Tag name in uppercase — "H1", "P" — READ-ONLY!
nodeName (text)
"#text"
nodeValue (element)
null! — elements have no nodeValue
nodeValue (text)
The actual text content
innerHTML
= firstChild.nodeValue (for simple text elements) — it's a property
getElementById()
Returns ONE element — it's a method
getElementsByTagName()
Returns HTMLCollection (all matches)
querySelector()
CSS selector — FIRST match only
querySelectorAll()
CSS selector — NodeList (all matches)
appendChild()
Adds element as last child
insertBefore(new, ref)
Adds new element BEFORE reference element
element.remove()
Modern way to remove element from DOM
innerHTML vs innerText
innerHTML renders HTML tags (XSS risk!) — innerText is plain text (SAFE)

🎨 CSS Quick Ref

CSS Rule
selector { property: value; } — property:value = Declaration
Priority Order
Inline > Internal > External > Browser default
.class
Class selector — matches all elements with that class
#id
ID selector — matches ONE element
E.class
Element E with specific class (e.g. p.center)
E > F
F is direct child of E only
E ~ F
All F siblings AFTER E (general sibling)
E + F
The F immediately after E (adjacent sibling)
E[attr=val]
Attribute selector — exact match
E[attr^=val]
Attribute starts with val
E[attr$=val]
Attribute ends with val
:first-child
E only if it IS the first child of its parent
:hover
When mouse is over element (single colon! :: is wrong)
:empty
Element with NO children
Margin
Space OUTSIDE element (between elements)
Padding
Space INSIDE element (between content & border)
background-attachment
fixed = stays in place while scrolling | scroll = moves with page

🚨 Common Exam Traps

220 is success?
FALSE! There's no code 220. Success = 200-299
External CSS = highest?
FALSE! Inline = highest priority
p:first-child
⚠️ Only if <p> IS the first child! If <h2> comes first → 0 matches
<img href="...">
WRONG! It's <img src="..."> — href is for <a> tags
nodeValue of element
= null! NOT the text. Use .innerHTML or .firstChild.nodeValue
nodeName = read-only
You can't change it! nodeValue IS writable (for text nodes)
div > p vs div ~ p
> = children INSIDE div | ~ = siblings AFTER div. Totally different!
::hover
WRONG! It's :hover (single colon). :: is for pseudo-elements like ::before
insertBefore(x, y)
x goes BEFORE y. First param = new element, Second = reference!
getElementsByTagName("p")
Gets ALL <p> on page — even nested inside <section> inside <div>!